Skip to content

Commit 84b8793

Browse files
authored
Removed helper function Get-FilePathMajorVersion (#2375)
1 parent 6c25e35 commit 84b8793

13 files changed

+614
-454
lines changed

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5252
- `SqlProtocol`
5353
- Refactored to use the public command `Get-SqlDscServerProtocolName` instead
5454
of the deprecated private function `Get-ProtocolNameProperties`
55-
([issue #2104](https://github.com/dsccommunity/SqlServerDsc/issues/2104)).
55+
56+
### Fixed
57+
58+
- Fixed all `Invoke-WebRequest` calls throughout the codebase to include the
59+
`-UseBasicParsing` parameter. This addresses a Windows PowerShell 5.1 security
60+
update (CVE-2025-54100) released December 9, 2025, which changed the default
61+
behavior of `Invoke-WebRequest` to require an interactive prompt unless
62+
`-UseBasicParsing` is specified. This change prevents failures in non-interactive
63+
CI environments. Affected files include integration tests, production code, and
64+
build scripts
65+
([issue #2376](https://github.com/dsccommunity/SqlServerDsc/issues/2376)).
66+
- `SqlRS`
67+
- Fixed integration tests failing with status code 0 when checking ReportServer
68+
and Reports site accessibility by implementing retry logic (up to 2 minutes) to
69+
handle timing issues where Reporting Services web services are not immediately
70+
ready after DSC configuration completes. On final retry attempt with status
71+
code 0, the exception is now re-thrown to provide detailed error diagnostics
72+
([issue #2376](https://github.com/dsccommunity/SqlServerDsc/issues/2376)).
5673
- Refactored to use the public command `Get-SqlDscServerProtocol` instead
5774
of the deprecated private function `Get-ServerProtocolObject`
5875
([issue #2104](https://github.com/dsccommunity/SqlServerDsc/issues/2104)).
@@ -121,6 +138,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
121138

122139
### Removed
123140

141+
- Removed helper function `Get-FilePathMajorVersion` from the SqlServerDsc.Common
142+
module. Refactored usages to use the command `Get-FileVersion` from the
143+
DscResource.Common module instead
124144
- Removed private function `Get-FileVersionInformation`. Use the command
125145
`Get-FileVersion` from the DscResource.Common module instead
126146
([issue #2373](https://github.com/dsccommunity/SqlServerDsc/issues/2373)).

source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function Get-TargetResource
215215

216216
Write-Verbose -Message ($script:localizedData.UsingPath -f $pathToSetupExecutable)
217217

218-
$SqlVersion = Get-FilePathMajorVersion -Path $pathToSetupExecutable
218+
$SqlVersion = (Get-FileVersion -Path $pathToSetupExecutable).ProductVersion.Split('.')[0]
219219
}
220220
else
221221
{
@@ -1082,7 +1082,7 @@ function Set-TargetResource
10821082

10831083
Write-Verbose -Message ($script:localizedData.UsingPath -f $pathToSetupExecutable)
10841084

1085-
$SqlVersion = Get-FilePathMajorVersion -Path $pathToSetupExecutable
1085+
$SqlVersion = (Get-FileVersion -Path $pathToSetupExecutable).ProductVersion.Split('.')[0]
10861086
}
10871087
else
10881088
{
@@ -2363,7 +2363,7 @@ function Test-TargetResource
23632363

23642364
if ($getTargetResourceParameters.Action -eq 'Upgrade')
23652365
{
2366-
$installerSqlVersion = Get-FilePathMajorVersion -Path (Join-Path -Path $sourcePath -ChildPath 'setup.exe')
2366+
$installerSqlVersion = (Get-FileVersion -Path (Join-Path -Path $sourcePath -ChildPath 'setup.exe')).ProductVersion.Split('.')[0]
23672367
$instanceSqlVersion = Get-SQLInstanceMajorVersion -InstanceName $InstanceName
23682368

23692369
if ($installerSQLVersion -gt $instanceSqlVersion)

source/DSCResources/DSC_SqlWindowsFirewall/DSC_SqlWindowsFirewall.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function Get-TargetResource
7979
$script:localizedData.UsingPath -f $pathToSetupExecutable
8080
)
8181

82-
$sqlVersion = Get-FilePathMajorVersion -Path $pathToSetupExecutable
82+
$sqlVersion = (Get-FileVersion -Path $pathToSetupExecutable).ProductVersion.Split('.')[0]
8383

8484
Write-Verbose -Message (
8585
$script:localizedData.MajorVersion -f $sqlVersion
@@ -405,7 +405,7 @@ function Set-TargetResource
405405
$script:localizedData.UsingPath -f $pathToSetupExecutable
406406
)
407407

408-
$sqlVersion = Get-FilePathMajorVersion -Path $pathToSetupExecutable
408+
$sqlVersion = (Get-FileVersion -Path $pathToSetupExecutable).ProductVersion.Split('.')[0]
409409

410410
Write-Verbose -Message (
411411
$script:localizedData.MajorVersion -f $sqlVersion

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
'Test-DscPropertyState'
4848
'Import-Assembly'
4949
'ConvertTo-ServerInstanceName'
50-
'Get-FilePathMajorVersion'
5150
'Test-FeatureFlag'
5251
)
5352

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,31 +1981,6 @@ function ConvertTo-ServerInstanceName
19811981
return $serverInstance
19821982
}
19831983

1984-
<#
1985-
.SYNOPSIS
1986-
Returns the SQL Server major version from the setup.exe executable provided
1987-
in the Path parameter.
1988-
1989-
.PARAMETER Path
1990-
String containing the path to the SQL Server setup.exe executable.
1991-
1992-
.NOTES
1993-
This function should be removed when it is not longer used, and instead
1994-
the command Get-FileVersion from the DscResource.Common module shall be used.
1995-
#>
1996-
function Get-FilePathMajorVersion
1997-
{
1998-
[CmdletBinding()]
1999-
param
2000-
(
2001-
[Parameter(Mandatory = $true)]
2002-
[System.String]
2003-
$Path
2004-
)
2005-
2006-
(Get-Item -Path $Path).VersionInfo.ProductVersion.Split('.')[0]
2007-
}
2008-
20091984
<#
20101985
.SYNOPSIS
20111986
Test if the specific feature flag should be enabled.

source/Public/Save-SqlDscSqlServerMediaFile.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function Save-SqlDscSqlServerMediaFile
166166
Write-Verbose -Message ($script:localizedData.SqlServerMediaFile_Save_DownloadingInformation -f $Url)
167167

168168
# Download the URL content.
169-
Invoke-WebRequest -Uri $Url -OutFile $downloadedFilePath | Out-Null
169+
Invoke-WebRequest -Uri $Url -OutFile $downloadedFilePath -UseBasicParsing | Out-Null
170170

171171
if ($Quiet.IsPresent)
172172
{

tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1

Lines changed: 90 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016',
172172
}
173173

174174
It 'Should be able to access the ReportServer site without any error' {
175-
# Wait for 1 minute for the ReportServer to be ready.
176-
Start-Sleep -Seconds 30
177-
178175
if ($script:sqlVersion -in @('140', '150', '160'))
179176
{
180177
# SSRS 2017 and 2019 do not support multiple instances
@@ -185,20 +182,52 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016',
185182
$reportServerUri = 'http://{0}/ReportServer_{1}' -f $env:COMPUTERNAME, $ConfigurationData.AllNodes.InstanceName
186183
}
187184

188-
try
189-
{
190-
$webRequestReportServer = Invoke-WebRequest -Uri $reportServerUri -UseDefaultCredentials
191-
# if the request finishes successfully this should return status code 200.
192-
$webRequestStatusCode = $webRequestReportServer.StatusCode -as [int]
193-
}
194-
catch
185+
# Retry logic to wait for ReportServer to be ready (up to 2 minutes)
186+
$maxRetries = 24
187+
$retryIntervalSeconds = 5
188+
$webRequestStatusCode = 0
189+
190+
for ($attempt = 1; $attempt -le $maxRetries; $attempt++)
195191
{
196-
<#
197-
If the request generated an exception i.e. "HTTP Error 503. The service is unavailable."
198-
we can pull the status code from the Exception.Response property.
199-
#>
200-
$webRequestResponse = $_.Exception.Response
201-
$webRequestStatusCode = $webRequestResponse.StatusCode -as [int]
192+
try
193+
{
194+
$webRequestReportServer = Invoke-WebRequest -Uri $reportServerUri -UseDefaultCredentials -UseBasicParsing -ErrorAction Stop
195+
# if the request finishes successfully this should return status code 200.
196+
$webRequestStatusCode = $webRequestReportServer.StatusCode -as [int]
197+
198+
if ($webRequestStatusCode -eq 200)
199+
{
200+
Write-Verbose -Message "ReportServer is accessible (attempt $attempt)." -Verbose
201+
break
202+
}
203+
}
204+
catch
205+
{
206+
<#
207+
If the request generated an exception i.e. "HTTP Error 503. The service is unavailable."
208+
we can pull the status code from the Exception.Response property.
209+
#>
210+
$webRequestResponse = $_.Exception.Response
211+
$webRequestStatusCode = $webRequestResponse.StatusCode -as [int]
212+
213+
if ($webRequestStatusCode -eq 0 -and $attempt -lt $maxRetries)
214+
{
215+
Write-Verbose -Message "ReportServer not yet accessible (attempt $attempt of $maxRetries). Waiting $retryIntervalSeconds seconds..." -Verbose
216+
Start-Sleep -Seconds $retryIntervalSeconds
217+
}
218+
elseif ($webRequestStatusCode -eq 0 -and $attempt -eq $maxRetries)
219+
{
220+
# On the last attempt with status code 0, re-throw to get error details
221+
Write-Verbose -Message "ReportServer still not accessible after $maxRetries attempts. Re-throwing exception for diagnostics." -Verbose
222+
throw $_
223+
}
224+
elseif ($webRequestStatusCode -ne 0)
225+
{
226+
# If we got an actual HTTP error code, break and let the assertion handle it
227+
Write-Verbose -Message "ReportServer returned HTTP status code $webRequestStatusCode (attempt $attempt)." -Verbose
228+
break
229+
}
230+
}
202231
}
203232

204233
$webRequestStatusCode | Should -BeExactly 200
@@ -215,20 +244,52 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016',
215244
$reportsUri = 'http://{0}/Reports_{1}' -f $env:COMPUTERNAME, $ConfigurationData.AllNodes.InstanceName
216245
}
217246

218-
try
219-
{
220-
$webRequestReportServer = Invoke-WebRequest -Uri $reportsUri -UseDefaultCredentials
221-
# if the request finishes successfully this should return status code 200.
222-
$webRequestStatusCode = $webRequestReportServer.StatusCode -as [int]
223-
}
224-
catch
247+
# Retry logic to wait for Reports site to be ready (up to 2 minutes)
248+
$maxRetries = 24
249+
$retryIntervalSeconds = 5
250+
$webRequestStatusCode = 0
251+
252+
for ($attempt = 1; $attempt -le $maxRetries; $attempt++)
225253
{
226-
<#
227-
If the request generated an exception i.e. "HTTP Error 503. The service is unavailable."
228-
we can pull the status code from the Exception.Response property.
229-
#>
230-
$webRequestResponse = $_.Exception.Response
231-
$webRequestStatusCode = $webRequestResponse.StatusCode -as [int]
254+
try
255+
{
256+
$webRequestReportServer = Invoke-WebRequest -Uri $reportsUri -UseDefaultCredentials -UseBasicParsing -ErrorAction Stop
257+
# if the request finishes successfully this should return status code 200.
258+
$webRequestStatusCode = $webRequestReportServer.StatusCode -as [int]
259+
260+
if ($webRequestStatusCode -eq 200)
261+
{
262+
Write-Verbose -Message "Reports site is accessible (attempt $attempt)." -Verbose
263+
break
264+
}
265+
}
266+
catch
267+
{
268+
<#
269+
If the request generated an exception i.e. "HTTP Error 503. The service is unavailable."
270+
we can pull the status code from the Exception.Response property.
271+
#>
272+
$webRequestResponse = $_.Exception.Response
273+
$webRequestStatusCode = $webRequestResponse.StatusCode -as [int]
274+
275+
if ($webRequestStatusCode -eq 0 -and $attempt -lt $maxRetries)
276+
{
277+
Write-Verbose -Message "Reports site not yet accessible (attempt $attempt of $maxRetries). Waiting $retryIntervalSeconds seconds..." -Verbose
278+
Start-Sleep -Seconds $retryIntervalSeconds
279+
}
280+
elseif ($webRequestStatusCode -eq 0 -and $attempt -eq $maxRetries)
281+
{
282+
# On the last attempt with status code 0, re-throw to get error details
283+
Write-Verbose -Message "Reports site still not accessible after $maxRetries attempts. Re-throwing exception for diagnostics." -Verbose
284+
throw $_
285+
}
286+
elseif ($webRequestStatusCode -ne 0)
287+
{
288+
# If we got an actual HTTP error code, break and let the assertion handle it
289+
Write-Verbose -Message "Reports site returned HTTP status code $webRequestStatusCode (attempt $attempt)." -Verbose
290+
break
291+
}
292+
}
232293
}
233294

234295
$webRequestStatusCode | Should -BeExactly 200

tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ BeforeAll {
8989

9090
Write-Verbose -Message ('Start downloading the {1} executable at {0}.' -f (Get-Date -Format 'yyyy-MM-dd hh:mm:ss'), $script:mockSourceMediaDisplayName) -Verbose
9191

92-
Invoke-WebRequest -Uri $script:mockSourceMediaUrl -OutFile $ConfigurationData.AllNodes.MediaPath
92+
Invoke-WebRequest -Uri $script:mockSourceMediaUrl -OutFile $ConfigurationData.AllNodes.MediaPath -UseBasicParsing
9393

9494
Write-Verbose -Message ('{1} executable file has SHA1 hash ''{0}''.' -f (Get-FileHash -Path $ConfigurationData.AllNodes.MediaPath -Algorithm 'SHA1').Hash, $script:mockSourceMediaDisplayName) -Verbose
9595

0 commit comments

Comments
 (0)