Skip to content

Commit f8711c8

Browse files
Reject whitespace-only command inputs
Cover API tokens, DDNS parameters, DNS filters, forward hosts, and smoke-test names at the parameter boundary. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent e7385a4 commit f8711c8

14 files changed

Lines changed: 55 additions & 0 deletions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function Connect-DomeneshopAccount {
4949
# The Domeneshop API token used as the Basic authentication username.
5050
[Parameter(Mandatory)]
5151
[ValidateNotNullOrEmpty()]
52+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
5253
[string] $Token,
5354

5455
# The Domeneshop API secret as a string or secure string.

src/functions/public/Ddns/Update-DomeneshopDdns.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ function Update-DomeneshopDdns {
4040
# The fully qualified hostname to update.
4141
[Parameter(Mandatory)]
4242
[ValidateNotNullOrEmpty()]
43+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
4344
[Alias('Host')]
4445
[string] $Hostname,
4546

4647
# The IPv4 or IPv6 address to publish.
4748
[Parameter()]
4849
[ValidateNotNullOrEmpty()]
50+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
4951
[Alias('IP')]
5052
[string] $MyIP,
5153

src/functions/public/Dns/Get-DomeneshopDnsRecord.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,20 @@ function Get-DomeneshopDnsRecord {
5151
# A hostname filter for list requests.
5252
[Parameter(ParameterSetName = 'List')]
5353
[ValidateNotNullOrEmpty()]
54+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
5455
[Alias('Host')]
5556
[string] $RecordHost,
5657

5758
# A DNS record type filter for list requests.
5859
[Parameter(ParameterSetName = 'List')]
5960
[ValidateNotNullOrEmpty()]
61+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
6062
[string] $Type,
6163

6264
# A record-data filter for list requests.
6365
[Parameter(ParameterSetName = 'List')]
6466
[ValidateNotNullOrEmpty()]
67+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
6568
[string] $Data,
6669

6770
# The stored credential context to use instead of the default.

src/functions/public/Forwards/Get-DomeneshopForward.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function Get-DomeneshopForward {
4646
# The hostname of a specific HTTP forward.
4747
[Parameter(Mandatory, ParameterSetName = 'Get by host')]
4848
[ValidateNotNullOrEmpty()]
49+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
4950
[Alias('Host')]
5051
[string] $ForwardHost,
5152

src/functions/public/Forwards/Remove-DomeneshopForward.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function Remove-DomeneshopForward {
4141
# The hostname of the HTTP forward to remove.
4242
[Parameter(Mandatory)]
4343
[ValidateNotNullOrEmpty()]
44+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
4445
[Alias('Host')]
4546
[string] $ForwardHost,
4647

src/functions/public/Forwards/Set-DomeneshopForward.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function Set-DomeneshopForward {
4545
# The hostname of the HTTP forward to update.
4646
[Parameter(Mandatory)]
4747
[ValidateNotNullOrEmpty()]
48+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
4849
[Alias('Host')]
4950
[string] $ForwardHost,
5051

src/functions/public/Get-PSModuleTest.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
# The name to include in the greeting.
3737
[Parameter(Mandatory)]
3838
[ValidateNotNullOrEmpty()]
39+
[ValidateScript({ -not [string]::IsNullOrWhiteSpace($_) })]
3940
[string] $Name
4041
)
4142

tests/Connect-DomeneshopAccount.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,10 @@ Describe 'Connect-DomeneshopAccount' {
109109

110110
Should -Invoke Set-Context -Times 0 -Exactly
111111
}
112+
113+
It 'rejects a whitespace-only API token' {
114+
{ Connect-DomeneshopAccount -Token ' ' -Secret 'secret' -Context 'demo' } | Should -Throw
115+
116+
Should -Invoke Set-Context -Times 0 -Exactly
117+
}
112118
}

tests/Get-DomeneshopDnsRecord.Tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ Describe 'Get-DomeneshopDnsRecord' {
3838
$Uri -eq 'https://api.domeneshop.no/v0/domains/42/dns/7'
3939
}
4040
}
41+
42+
It 'rejects whitespace-only list filters' {
43+
{ Get-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -RecordHost ' ' } | Should -Throw
44+
{ Get-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -Type ' ' } | Should -Throw
45+
{ Get-DomeneshopDnsRecord -Context 'demo' -DomainID 42 -Data ' ' } | Should -Throw
46+
47+
Should -Invoke Invoke-DomeneshopApiRequest -Times 0 -Exactly
48+
}
4149
}

tests/Get-DomeneshopForward.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ Describe 'Get-DomeneshopForward' {
3838
$Uri -eq 'https://api.domeneshop.no/v0/domains/42/forwards/home%20office'
3939
}
4040
}
41+
42+
It 'rejects whitespace-only forward hosts' {
43+
{ Get-DomeneshopForward -Context 'demo' -DomainID 42 -ForwardHost ' ' } | Should -Throw
44+
45+
Should -Invoke Invoke-DomeneshopApiRequest -Times 0 -Exactly
46+
}
4147
}

0 commit comments

Comments
 (0)