513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
42 lines
2.0 KiB
C#
42 lines
2.0 KiB
C#
using Microsoft.AspNetCore.HttpOverrides;
|
|
using ZB.MOM.WW.ScadaBridge.Security;
|
|
using Xunit;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Security.Tests;
|
|
|
|
public class ForwardedHeadersSetupTests
|
|
{
|
|
/// <summary>Verifies that building with forwarded headers disabled returns null.</summary>
|
|
[Fact]
|
|
public void Build_Disabled_ReturnsNull()
|
|
=> Assert.Null(ForwardedHeadersSetup.Build(new ForwardedHeadersSecurityOptions { Enabled = false }));
|
|
|
|
/// <summary>Verifies that enabling forwarded headers parses the proxies and networks and clears the default allow-lists.</summary>
|
|
[Fact]
|
|
public void Build_Enabled_ParsesProxiesAndNetworks_AndClearsDefaults()
|
|
{
|
|
var built = ForwardedHeadersSetup.Build(new ForwardedHeadersSecurityOptions
|
|
{
|
|
Enabled = true,
|
|
KnownProxies = ["10.5.0.9"],
|
|
KnownNetworks = ["172.16.0.0/12"],
|
|
})!;
|
|
Assert.Equal(ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto, built.ForwardedHeaders);
|
|
Assert.Equal(1, built.ForwardLimit);
|
|
Assert.Single(built.KnownProxies); // ONLY the configured proxy —
|
|
Assert.DoesNotContain(System.Net.IPAddress.IPv6Loopback, // the loopback default is cleared
|
|
built.KnownProxies);
|
|
Assert.Single(built.KnownIPNetworks); // net10 successor to the deprecated KnownNetworks
|
|
}
|
|
|
|
/// <summary>Verifies that a malformed proxy or network entry throws at startup.</summary>
|
|
/// <param name="proxy">The proxy address entry under test.</param>
|
|
/// <param name="network">The network CIDR entry under test.</param>
|
|
[Theory]
|
|
[InlineData("not-an-ip", "172.16.0.0/12")]
|
|
[InlineData("10.5.0.9", "not-a-cidr")]
|
|
public void Build_MalformedEntry_ThrowsAtStartup(string proxy, string network)
|
|
=> Assert.ThrowsAny<Exception>(() => ForwardedHeadersSetup.Build(
|
|
new ForwardedHeadersSecurityOptions { Enabled = true, KnownProxies = [proxy], KnownNetworks = [network] }));
|
|
}
|