File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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*'
You can’t perform that action at this time.
0 commit comments