@@ -71,16 +71,19 @@ private TestProxy(string proxyPath)
7171 EnvironmentVariables =
7272 {
7373 [ "ASPNETCORE_URLS" ] = $ "http://{ IpAddress } :0;https://{ IpAddress } :0",
74- [ "Logging__LogLevel__Microsoft" ] = "Information"
74+ [ "Logging__LogLevel__Microsoft.Hosting.Lifetime" ] = "Information" ,
75+ [ "ASPNETCORE_Kestrel__Certificates__Default__Path" ] = Path . Combine (
76+ TestEnvironment . RepositoryRoot ,
77+ "eng" ,
78+ "common" ,
79+ "testproxy" ,
80+ "dotnet-devcert.pfx" ) ,
81+ [ "ASPNETCORE_Kestrel__Certificates__Default__Password" ] = "password"
7582 }
7683 } ;
7784
78- if ( ! TestEnvironment . GlobalIsRunningInCI )
79- {
80- ImportDevCertIfNeeded ( ) ;
81- }
82-
8385 _testProxyProcess = Process . Start ( testProxyProcessInfo ) ;
86+
8487 ProcessTracker . Add ( _testProxyProcess ) ;
8588 _ = Task . Run (
8689 ( ) =>
@@ -95,7 +98,7 @@ private TestProxy(string proxyPath)
9598 } ) ;
9699
97100 int lines = 0 ;
98- while ( ( _proxyPortHttp == null || _proxyPortHttps == null ) && lines ++ < 50 )
101+ while ( ( _proxyPortHttp == null || _proxyPortHttps == null ) && lines ++ < 20 )
99102 {
100103 string outputLine = _testProxyProcess . StandardOutput . ReadLine ( ) ;
101104 // useful for debugging
@@ -114,7 +117,11 @@ private TestProxy(string proxyPath)
114117
115118 if ( _proxyPortHttp == null || _proxyPortHttps == null )
116119 {
117- throw new InvalidOperationException ( "Failed to start the test proxy." ) ;
120+ CheckForErrors ( ) ;
121+ // if no errors, fallback to this exception
122+ throw new InvalidOperationException ( "Failed to start the test proxy. One or both of the ports was not populated." + Environment . NewLine +
123+ $ "http: { _proxyPortHttp } " + Environment . NewLine +
124+ $ "https: { _proxyPortHttps } ") ;
118125 }
119126
120127 // we need to use https when talking to test proxy admin endpoint so that we can establish the connection before any
@@ -175,46 +182,6 @@ public static TestProxy Start()
175182 }
176183 }
177184
178- private static void ImportDevCertIfNeeded ( )
179- {
180- ProcessStartInfo checkCertProcessInfo = new ProcessStartInfo (
181- s_dotNetExe ,
182- "dev-certs https --check --verbose" )
183- {
184- UseShellExecute = false ,
185- RedirectStandardOutput = true
186- } ;
187-
188- Process checkCertProcess = Process . Start ( checkCertProcessInfo ) ;
189- string output = checkCertProcess . StandardOutput . ReadToEnd ( ) ;
190- if ( ! output . Contains ( "A valid certificate was found." ) &&
191- // .NET 6.0 SDK has a different output
192- ! output . Contains ( "CN=localhost" ) )
193- {
194- TestContext . Progress . WriteLine ( "Importing certificate..." ) ;
195- checkCertProcess . WaitForExit ( ) ;
196- var certPath = Path . Combine ( TestEnvironment . RepositoryRoot , "eng" , "common" , "testproxy" , "dotnet-devcert.pfx" ) ;
197- ProcessStartInfo processInfo = new ProcessStartInfo (
198- s_dotNetExe ,
199- $ "dev-certs https --clean --import { certPath } --password=\" password\" ")
200- {
201- UseShellExecute = false
202- } ;
203- Process . Start ( processInfo ) . WaitForExit ( ) ;
204- processInfo = new ProcessStartInfo (
205- s_dotNetExe ,
206- $ "dev-certs https --trust")
207- {
208- UseShellExecute = false
209- } ;
210- Process . Start ( processInfo ) . WaitForExit ( ) ;
211- }
212- else
213- {
214- checkCertProcess . WaitForExit ( ) ;
215- }
216- }
217-
218185 private static bool TryParsePort ( string output , string scheme , out int ? port )
219186 {
220187 if ( output == null )
0 commit comments