-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle missing X-Forwarded-For header in TableErrorLog (#9444)
This helps reduce debugging locally when AzureStorage is being used.
- Loading branch information
1 parent
659510b
commit a656006
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tests/NuGetGallery.Core.Facts/Infrastructure/TableErrorLogFacts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Linq; | ||
using Elmah; | ||
using Xunit; | ||
|
||
namespace NuGetGallery.Infrastructure | ||
{ | ||
public class TableErrorLogFacts | ||
{ | ||
public class TheObfuscateMethod | ||
{ | ||
[Fact] | ||
public void HandlesMissingForwardedHeader() | ||
{ | ||
// Arrange | ||
var error = new Error(); | ||
|
||
// Act | ||
TableErrorLog.Obfuscate(error); | ||
|
||
// Assert | ||
Assert.DoesNotContain("HTTP_X_FORWARDED_FOR", error.ServerVariables.Keys.Cast<string>()); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData(",", ",")] | ||
[InlineData(" ", " ")] | ||
[InlineData("127.0.0.1", "127.0.0.0")] | ||
[InlineData("127.1.2.3,127.1.2.4", "127.1.2.0,127.1.2.0")] | ||
[InlineData("127.1.2.3 , 127.1.2.4", "127.1.2.0,127.1.2.0")] | ||
public void ObfuscatesForwardedHeader(string input, string expected) | ||
{ | ||
// Arrange | ||
var error = new Error(); | ||
error.ServerVariables["HTTP_X_FORWARDED_FOR"] = input; | ||
|
||
// Act | ||
TableErrorLog.Obfuscate(error); | ||
|
||
// Assert | ||
Assert.Equal(expected, error.ServerVariables["HTTP_X_FORWARDED_FOR"]); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters