Skip to content

Commit

Permalink
[tests] Fix CRLF issues in M.E.Http
Browse files Browse the repository at this point in the history
Fixes: dotnet#52135

When running `Microsoft.Extensions.Http` tests on windows and
targeting `Browser`, the line ending differs between host and target
systems. Use helper `LineEndingsHelper.Normalize` method to update
expected strings.

The `Browser` Environment.NewLine is `\n`, while windows use `\r\n`.
https://github.com/dotnet/runtime/blob/5bd0edfe860e41bdfd690d3743e730594307292e/src/libraries/System.Private.CoreLib/src/System/Environment.UnixOrBrowser.cs#L51
  • Loading branch information
radekdoulik committed May 13, 2021
1 parent 8b6f404 commit fddb023
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -50,47 +51,47 @@ public async Task RedactHeaderValueWithHeaderList_ValueIsRedactedBeforeLogging()
m.EventId == LoggingScopeHttpMessageHandler.Log.EventIds.RequestHeader &&
m.LoggerName == "System.Net.Http.HttpClient.test.LogicalHandler";
}));
Assert.StartsWith(
Assert.StartsWith(LineEndingsHelper.Normalize(
@"Request Headers:
Authorization: *
Cache-Control: no-cache
", message.Message);
"), message.Message);

message = Assert.Single(messages.Where(m =>
{
return
m.EventId == LoggingHttpMessageHandler.Log.EventIds.RequestHeader &&
m.LoggerName == "System.Net.Http.HttpClient.test.ClientHandler";
}));
Assert.StartsWith(
Assert.StartsWith(LineEndingsHelper.Normalize(
@"Request Headers:
Authorization: *
Cache-Control: no-cache
", message.Message);
"), message.Message);

message = Assert.Single(messages.Where(m =>
{
return
m.EventId == LoggingHttpMessageHandler.Log.EventIds.ResponseHeader &&
m.LoggerName == "System.Net.Http.HttpClient.test.ClientHandler";
}));
Assert.StartsWith(
Assert.StartsWith(LineEndingsHelper.Normalize(
@"Response Headers:
X-Sensitive: *
Y-Non-Sensitive: innocuous value
", message.Message);
"), message.Message);

message = Assert.Single(messages.Where(m =>
{
return
m.EventId == LoggingScopeHttpMessageHandler.Log.EventIds.ResponseHeader &&
m.LoggerName == "System.Net.Http.HttpClient.test.LogicalHandler";
}));
Assert.StartsWith(
Assert.StartsWith(LineEndingsHelper.Normalize(
@"Response Headers:
X-Sensitive: *
Y-Non-Sensitive: innocuous value
", message.Message);
"), message.Message);
}

[Fact]
Expand Down Expand Up @@ -131,47 +132,47 @@ public async Task RedactHeaderValueWithPredicate_ValueIsRedactedBeforeLogging()
m.EventId == LoggingScopeHttpMessageHandler.Log.EventIds.RequestHeader &&
m.LoggerName == "System.Net.Http.HttpClient.test.LogicalHandler";
}));
Assert.StartsWith(
Assert.StartsWith(LineEndingsHelper.Normalize(
@"Request Headers:
Authorization: *
Cache-Control: no-cache
", message.Message);
"), message.Message);

message = Assert.Single(messages.Where(m =>
{
return
m.EventId == LoggingHttpMessageHandler.Log.EventIds.RequestHeader &&
m.LoggerName == "System.Net.Http.HttpClient.test.ClientHandler";
}));
Assert.StartsWith(
Assert.StartsWith(LineEndingsHelper.Normalize(
@"Request Headers:
Authorization: *
Cache-Control: no-cache
", message.Message);
"), message.Message);

message = Assert.Single(messages.Where(m =>
{
return
m.EventId == LoggingHttpMessageHandler.Log.EventIds.ResponseHeader &&
m.LoggerName == "System.Net.Http.HttpClient.test.ClientHandler";
}));
Assert.StartsWith(
Assert.StartsWith(LineEndingsHelper.Normalize(
@"Response Headers:
X-Sensitive: *
Y-Non-Sensitive: innocuous value
", message.Message);
"), message.Message);

message = Assert.Single(messages.Where(m =>
{
return
m.EventId == LoggingScopeHttpMessageHandler.Log.EventIds.ResponseHeader &&
m.LoggerName == "System.Net.Http.HttpClient.test.LogicalHandler";
}));
Assert.StartsWith(
Assert.StartsWith(LineEndingsHelper.Normalize(
@"Response Headers:
X-Sensitive: *
Y-Non-Sensitive: innocuous value
", message.Message);
"), message.Message);
}

private class TestMessageHandler : HttpClientHandler
Expand Down
1 change: 0 additions & 1 deletion src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@

<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(BrowserHost)' == 'windows' and '$(RunDisabledWasmTestsOnWindows)' != 'true'">
<!-- Issue: https://github.com/dotnet/runtime/issues/52138 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Http\tests\Microsoft.Extensions.Http.Tests\Microsoft.Extensions.Http.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Json\tests\System.Text.Json.Tests/System.Text.Json.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.CodeDom\tests\System.CodeDom.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.Compression\tests\System.IO.Compression.Tests.csproj" />
Expand Down

0 comments on commit fddb023

Please sign in to comment.