-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2240 from microsoft/lusassl-ianatimezoneissuedete…
…ction Check for invalid IanaTimeZoneMappings.xml added
- Loading branch information
Showing
7 changed files
with
1,250 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ hostnames | |
HRESULT | ||
hsts | ||
httperr | ||
iana | ||
ietf | ||
imap | ||
inetsrv | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
Diagnostics/HealthChecker/Analyzer/Test-IanaTimeZoneMapping.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
. $PSScriptRoot\..\..\..\Shared\ErrorMonitorFunctions.ps1 | ||
|
||
function Test-IanaTimeZoneMapping { | ||
[CmdletBinding(DefaultParameterSetName = "FilePath")] | ||
param( | ||
[Parameter(Mandatory = $true, ParameterSetName = "FilePath")] | ||
[string]$FilePath, | ||
|
||
[Parameter(Mandatory = $true, ParameterSetName = "MappingFile")] | ||
[System.Xml.XmlNode]$IanaMappingFile | ||
) | ||
|
||
begin { | ||
$xmlMap = New-Object System.Collections.Generic.HashSet[string] | ||
$xmlMissingAttributesList = New-Object System.Collections.Generic.HashSet[object] | ||
$xmlDuplicateEntriesList = New-Object System.Collections.Generic.List[object] | ||
} process { | ||
|
||
if ($PSCmdlet.ParameterSetName -eq "FilePath") { | ||
if ((Test-Path -Path $FilePath) -eq $false) { | ||
Write-Verbose "Path: $FilePath doesn't exist" | ||
|
||
return | ||
} | ||
|
||
try { | ||
[xml]$IanaMappingFile = Get-Content -Path $FilePath -ErrorAction Stop | ||
} catch { | ||
Write-Verbose "Exception while trying to import file: $FilePath - Exception: $_" | ||
Invoke-CatchActions | ||
} | ||
} | ||
|
||
try { | ||
$nodeList = $IanaMappingFile.SelectNodes("//Map") | ||
|
||
if ($null -eq $nodeList) { | ||
Write-Verbose "Failed to process XML file" | ||
|
||
return | ||
} | ||
|
||
foreach ($node in $nodeList) { | ||
|
||
[string]$iana = $node.Attributes["IANA"].Value | ||
[string]$win = $node.Attributes["Win"].Value | ||
$xmlMapKey = "$iana|$win" | ||
|
||
if ([System.String]::IsNullOrEmpty($iana) -or | ||
[System.String]::IsNullOrEmpty($win)) { | ||
Write-Verbose "Map node missing required attribute: $xmlMapKey" | ||
$xmlMissingAttributesList.Add($node) | ||
|
||
continue | ||
} | ||
|
||
if ($xmlMap -contains $xmlMapKey) { | ||
Write-Verbose "Duplicate entry found: $xmlMapKey" | ||
$xmlDuplicateEntriesList.Add($node) | ||
|
||
continue | ||
} | ||
|
||
[void]$xmlMap.Add($xmlMapKey) | ||
} | ||
} catch { | ||
Write-Verbose "Exception while processing content of the IanaTimeZoneMapping file - Exception: $_" | ||
Invoke-CatchActions | ||
} | ||
} end { | ||
return [PSCustomObject]@{ | ||
NodeMissingAttributes = $xmlMissingAttributesList | ||
DuplicateEntries = $xmlDuplicateEntriesList | ||
} | ||
} | ||
} |
Oops, something went wrong.