Skip to content

Commit ee5fc08

Browse files
adityapatwardhanTravisEz13
authored andcommitted
Remove dotnet dependency to start WebListener (PowerShell#8390)
WebListener.exe (which was already being built) is sufficient to start web listener. Remove the dependency on `dotnet` being present to start the web listener. Use `Start-Process` instead of `Start-Job` to launch the WebListener.
1 parent ac2b453 commit ee5fc08

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,20 @@ Describe "Test-Connection" -tags "CI" {
257257
$result | Should -BeTrue
258258
}
259259
}
260+
}
260261

261-
Context "Connection" {
262-
BeforeAll {
263-
# Ensure the local host listen on port 80
264-
$WebListener = Start-WebListener
265-
}
262+
Describe "Connection" -Tag "CI", "RequireAdminOnWindows" {
263+
BeforeAll {
264+
# Ensure the local host listen on port 80
265+
$WebListener = Start-WebListener
266+
$UnreachableAddress = "10.11.12.13"
267+
}
266268

267-
It "Test connection to local host port 80" {
268-
Test-Connection '127.0.0.1' -TCPPort $WebListener.HttpPort | Should -BeTrue
269-
}
269+
It "Test connection to local host port 80" {
270+
Test-Connection '127.0.0.1' -TCPPort $WebListener.HttpPort | Should -BeTrue
271+
}
270272

271-
It "Test connection to unreachable host port 80" {
272-
Test-Connection $UnreachableAddress -TCPPort 80 -TimeOut 1 | Should -BeFalse
273-
}
273+
It "Test connection to unreachable host port 80" {
274+
Test-Connection $UnreachableAddress -TCPPort 80 -TimeOut 1 | Should -BeFalse
274275
}
275276
}

test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ $redirectTests = @(
367367
@{redirectType = 'relative'; redirectedMethod = 'GET'}
368368
)
369369

370-
Describe "Invoke-WebRequest tests" -Tags "Feature" {
370+
Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" {
371371
BeforeAll {
372372
$WebListener = Start-WebListener
373373
}
@@ -1785,7 +1785,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" {
17851785
}
17861786
}
17871787

1788-
Describe "Invoke-RestMethod tests" -Tags "Feature" {
1788+
Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" {
17891789
BeforeAll {
17901790
$WebListener = Start-WebListener
17911791
}
@@ -3069,7 +3069,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" {
30693069
}
30703070
}
30713071

3072-
Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Feature" {
3072+
Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Feature", "RequireAdminOnWindows" {
30733073
BeforeAll {
30743074
$WebListener = Start-WebListener
30753075
}
@@ -3149,7 +3149,7 @@ Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Featu
31493149
}
31503150
}
31513151

3152-
Describe "Web cmdlets tests using the cmdlet's aliases" -Tags "CI" {
3152+
Describe "Web cmdlets tests using the cmdlet's aliases" -Tags "CI", "RequireAdminOnWindows" {
31533153
BeforeAll {
31543154
$WebListener = Start-WebListener
31553155
}

test/tools/Modules/WebListener/WebListener.psm1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function Start-WebListener
120120
}
121121

122122
$initTimeoutSeconds = 15
123-
$appDll = 'WebListener.dll'
123+
$appExe = (get-command WebListener).Path
124124
$serverPfx = 'ServerCert.pfx'
125125
$serverPfxPassword = New-RandomHexString
126126
$clientPfx = 'ClientCert.pfx'
@@ -136,22 +136,23 @@ function Start-WebListener
136136
$Job = Start-Job {
137137
$path = Split-Path -parent (get-command WebListener).Path -Verbose
138138
Push-Location $path -Verbose
139-
'appDLL: {0}' -f $using:appDll
139+
'appEXE: {0}' -f $using:appExe
140140
'serverPfxPath: {0}' -f $using:serverPfxPath
141141
'serverPfxPassword: {0}' -f $using:serverPfxPassword
142142
'HttpPort: {0}' -f $using:HttpPort
143143
'Https: {0}' -f $using:HttpsPort
144144
'Tls11Port: {0}' -f $using:Tls11Port
145145
'TlsPort: {0}' -f $using:TlsPort
146146
$env:ASPNETCORE_ENVIRONMENT = 'Development'
147-
dotnet $using:appDll $using:serverPfxPath $using:serverPfxPassword $using:HttpPort $using:HttpsPort $using:Tls11Port $using:TlsPort
147+
& $using:appExe $using:serverPfxPath $using:serverPfxPassword $using:HttpPort $using:HttpsPort $using:Tls11Port $using:TlsPort
148148
}
149+
149150
$Script:WebListener = [WebListener]@{
150151
HttpPort = $HttpPort
151152
HttpsPort = $HttpsPort
152153
Tls11Port = $Tls11Port
153154
TlsPort = $TlsPort
154-
Job = $Job
155+
Job = $Job
155156
}
156157

157158
# Count iterations of $sleepMilliseconds instead of using system time to work around possible CI VM sleep/delays
@@ -172,8 +173,7 @@ function Start-WebListener
172173
$jobVerbose = $Job.ChildJobs[0].Verbose | Out-String
173174
$Job | Stop-Job
174175
$Job | Remove-Job -Force
175-
$message = 'WebListener did not start before the timeout was reached.{0}Errors:{0}{1}{0}Output:{0}{2}{0}Verbose:{0}{3}' -f
176-
([System.Environment]::NewLine), $jobErrors, $jobOutput, $jobVerbose
176+
$message = 'WebListener did not start before the timeout was reached.{0}Errors:{0}{1}{0}Output:{0}{2}{0}Verbose:{0}{3}' -f ([System.Environment]::NewLine), $jobErrors, $jobOutput, $jobVerbose
177177
throw $message
178178
}
179179
return $Script:WebListener

0 commit comments

Comments
 (0)