Skip to content

Commit

Permalink
Fix HttpWebRequest proxy test (dotnet/corefx#36191)
Browse files Browse the repository at this point in the history
Change test so that it doesn't trip up CredScan.

Fixes dotnet/corefx#36187

Commit migrated from dotnet/corefx@d09d8f7
  • Loading branch information
davidsh authored Mar 20, 2019
1 parent f094cb0 commit 7396d92
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,10 +1321,9 @@ public void Proxy_GetDefault_ExpectNotNull(Uri remoteServer)
[Fact]
public async Task ProxySetViaEnvironmentVariable_DefaultProxyCredentialsUsed()
{
const string ExpectedUsername = "rightusername";
const string ExpectedPassword = "rightpassword";
var cred = new NetworkCredential(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"));
LoopbackServer.Options options =
new LoopbackServer.Options { IsProxy = true, Username = ExpectedUsername, Password = ExpectedPassword };
new LoopbackServer.Options { IsProxy = true, Username = cred.UserName, Password = cred.Password };

await LoopbackServer.CreateServerAsync(async (proxyServer, proxyUri) =>
{
Expand All @@ -1337,9 +1336,9 @@ await LoopbackServer.CreateServerAsync(async (proxyServer, proxyUri) =>
proxyTask = proxyServer.AcceptConnectionPerformAuthenticationAndCloseAsync("Proxy-Authenticate: Basic realm=\"NetCore\"\r\n");
psi.Environment.Add("http_proxy", $"http://{proxyUri.Host}:{proxyUri.Port}");

RemoteInvoke(async () =>
RemoteInvoke(async (user, pw) =>
{
WebRequest.DefaultWebProxy.Credentials = new NetworkCredential(ExpectedUsername, ExpectedPassword);
WebRequest.DefaultWebProxy.Credentials = new NetworkCredential(user, pw);
HttpWebRequest request = HttpWebRequest.CreateHttp(Configuration.Http.RemoteEchoServer);

using (var response = (HttpWebResponse) await request.GetResponseAsync())
Expand All @@ -1348,7 +1347,7 @@ await LoopbackServer.CreateServerAsync(async (proxyServer, proxyUri) =>
}

return SuccessExitCode;
}, new RemoteInvokeOptions { StartInfo = psi }).Dispose();
}, cred.UserName, cred.Password, new RemoteInvokeOptions { StartInfo = psi }).Dispose();

await proxyTask;
}, options);
Expand Down

0 comments on commit 7396d92

Please sign in to comment.