mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-09 09:31:15 +10:00
Add DNS-over-HTTPS (DoH) support (#4856)
* feat: Add DoH templates for DNS providers in configuration * feat: Implement DoH support for DNS configuration and management * feat(pester): enhance DNS tests to include DoH server address handling and template application * fix: address codex feedback * fix: update existing DoH server entries * fix: enable DoH auto-upgrade * fix: handle DNS setup failures * fix: remove DoH state on DHCP reset
This commit is contained in:
+77
-3
@@ -23,6 +23,20 @@ BeforeAll {
|
||||
param($Message, $Level, $Component)
|
||||
}
|
||||
|
||||
function Add-DnsClientDohServerAddress {
|
||||
param($ServerAddress, $DohTemplate, $AllowFallbackToUdp, $AutoUpgrade, $ErrorAction)
|
||||
}
|
||||
function Set-DnsClientDohServerAddress {
|
||||
param($ServerAddress, $DohTemplate, $AllowFallbackToUdp, $AutoUpgrade, $ErrorAction)
|
||||
}
|
||||
function Get-DnsClientDohServerAddress {
|
||||
param($ServerAddress, $ErrorAction)
|
||||
}
|
||||
function Remove-DnsClientDohServerAddress {
|
||||
param($ServerAddress, $Confirm, $ErrorAction)
|
||||
}
|
||||
function Clear-DnsClientCache { }
|
||||
|
||||
. (Join-Path $script:repoRoot "functions\private\Set-WinUtilDNS.ps1")
|
||||
}
|
||||
|
||||
@@ -36,6 +50,7 @@ Describe "Set-WinUtilDNS" {
|
||||
Secondary = "1.0.0.1"
|
||||
Primary6 = "2606:4700:4700::1111"
|
||||
Secondary6 = "2606:4700:4700::1001"
|
||||
DohTemplate = "https://cloudflare-dns.com/dns-query"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +61,7 @@ Describe "Set-WinUtilDNS" {
|
||||
Name = "Ethernet"
|
||||
Status = "Up"
|
||||
ifIndex = 7
|
||||
InterfaceGuid = "{1234-5678-90AB-CDEF}"
|
||||
}
|
||||
}
|
||||
Mock Set-DnsClientServerAddress { }
|
||||
@@ -53,13 +69,25 @@ Describe "Set-WinUtilDNS" {
|
||||
Mock Write-WinUtilLog { }
|
||||
Mock Write-Warning { }
|
||||
Mock Write-Host { }
|
||||
|
||||
Mock Get-Command { return $true } -ParameterFilter { $Name -eq "Add-DnsClientDohServerAddress" }
|
||||
Mock Add-DnsClientDohServerAddress { }
|
||||
Mock Set-DnsClientDohServerAddress { }
|
||||
Mock Get-DnsClientDohServerAddress { return $null }
|
||||
Mock Remove-DnsClientDohServerAddress { }
|
||||
Mock Test-Path { return $false }
|
||||
Mock Get-ChildItem { }
|
||||
Mock New-Item { }
|
||||
Mock New-ItemProperty { }
|
||||
Mock Remove-Item { }
|
||||
Mock Clear-DnsClientCache { }
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
Remove-Variable -Name sync -Scope Script -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
It "sets IPv4 and IPv6 DNS server addresses separately" {
|
||||
It "sets IPv4 and IPv6 DNS server addresses separately and applies DoH templates" {
|
||||
Set-WinUtilDNS -DNSProvider "Cloudflare"
|
||||
|
||||
Should -Invoke -CommandName Set-DnsClientServerAddress -Times 1 -Exactly -ParameterFilter {
|
||||
@@ -77,9 +105,51 @@ Describe "Set-WinUtilDNS" {
|
||||
Should -Invoke -CommandName Set-DnsClientServerAddress -Times 0 -Exactly -ParameterFilter {
|
||||
$ServerAddresses.Count -eq 4
|
||||
}
|
||||
Should -Invoke -CommandName Add-DnsClientDohServerAddress -Times 4 -Exactly
|
||||
Should -Invoke -CommandName New-ItemProperty -Times 4 -ParameterFilter {
|
||||
$Name -eq "DohFlags" -and $Value -eq 1
|
||||
}
|
||||
Should -Invoke -CommandName Clear-DnsClientCache -Times 1 -Exactly
|
||||
}
|
||||
|
||||
It "resets DNS to DHCP for IPv4 and IPv6" {
|
||||
It "updates an existing DoH entry with the selected provider settings" {
|
||||
Mock Get-DnsClientDohServerAddress {
|
||||
if ($ServerAddress -eq "1.1.1.1") {
|
||||
return [pscustomobject]@{ ServerAddress = $ServerAddress }
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
Set-WinUtilDNS -DNSProvider "Cloudflare"
|
||||
|
||||
Should -Invoke -CommandName Set-DnsClientDohServerAddress -Times 1 -Exactly -ParameterFilter {
|
||||
$ServerAddress -eq "1.1.1.1" -and
|
||||
$DohTemplate -eq "https://cloudflare-dns.com/dns-query" -and
|
||||
$AllowFallbackToUdp -eq $false -and
|
||||
$AutoUpgrade -eq $true
|
||||
}
|
||||
Should -Invoke -CommandName Add-DnsClientDohServerAddress -Times 3 -Exactly
|
||||
}
|
||||
|
||||
It "resets DNS to DHCP and removes the applied DoH configuration" {
|
||||
Mock Test-Path { return $true } -ParameterFilter { $Path -like "*DohInterfaceSettings*" }
|
||||
Mock Get-ChildItem {
|
||||
if ($Path -like "*\Doh6") {
|
||||
return @(
|
||||
[pscustomobject]@{ PSChildName = "2606:4700:4700::1111" }
|
||||
[pscustomobject]@{ PSChildName = "2606:4700:4700::1001" }
|
||||
)
|
||||
}
|
||||
|
||||
return @(
|
||||
[pscustomobject]@{ PSChildName = "1.1.1.1" }
|
||||
[pscustomobject]@{ PSChildName = "1.0.0.1" }
|
||||
)
|
||||
}
|
||||
Mock Get-DnsClientDohServerAddress {
|
||||
[pscustomobject]@{ ServerAddress = $ServerAddress }
|
||||
}
|
||||
|
||||
Set-WinUtilDNS -DNSProvider "DHCP"
|
||||
|
||||
Should -Invoke -CommandName Set-DnsClientServerAddress -Times 1 -Exactly -ParameterFilter {
|
||||
@@ -102,6 +172,10 @@ Describe "Set-WinUtilDNS" {
|
||||
$Arguments[4] -eq "name=Ethernet" -and
|
||||
$Arguments[5] -eq "source=dhcp"
|
||||
}
|
||||
Should -Invoke -CommandName Remove-Item -Times 1 -Exactly -ParameterFilter {
|
||||
$Path -like "*DohInterfaceSettings*" -and $Recurse -eq $true -and $Force -eq $true
|
||||
}
|
||||
Should -Invoke -CommandName Remove-DnsClientDohServerAddress -Times 4 -Exactly
|
||||
}
|
||||
|
||||
It "catches DNS setter failures so the tweak runspace can continue" {
|
||||
@@ -112,7 +186,7 @@ Describe "Set-WinUtilDNS" {
|
||||
Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter {
|
||||
$Level -eq "ERROR" -and
|
||||
$Component -eq "DNS" -and
|
||||
$Message -like "Unable to set DNS provider Cloudflare*"
|
||||
$Message -like "DNS provider Cloudflare was not completed: *"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user