Skip to content

Commit 6868734

Browse files
Don't import dev cert (Azure#25984)
* Don't import dev cert * Fix error * Microsoft.Hosting * Bump version * PR fb * revert session file
1 parent 1458224 commit 6868734

File tree

3 files changed

+16
-56
lines changed

3 files changed

+16
-56
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
</ItemGroup>
263263

264264
<PropertyGroup>
265-
<TestProxyVersion>1.0.0-dev.20211215.1</TestProxyVersion>
265+
<TestProxyVersion>1.0.0-dev.20211216.1</TestProxyVersion>
266266
</PropertyGroup>
267267

268268
</Project>

eng/scripts/Language-Settings.ps1

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,3 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata) {
521521
}
522522
Set-Content -Path $DocConfigFile -Value $outputLines
523523
}
524-
525-
function Import-Dev-Cert-net
526-
{
527-
Write-Host "Importing dev certificate"
528-
dotnet dev-certs https --clean --import eng/common/testproxy/dotnet-devcert.pfx --password="password"
529-
dotnet dev-certs https --trust
530-
}

sdk/core/Azure.Core.TestFramework/src/TestProxy.cs

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)