Table of Contents

Class ForwardedHeadersExtensionsCoverageTests

Namespace
ProjectTemplate.Web.Tests
Assembly
ProjectTemplate.Web.Tests.dll
public sealed class ForwardedHeadersExtensionsCoverageTests
Inheritance
ForwardedHeadersExtensionsCoverageTests
Inherited Members

Methods

AddApplicationForwardedHeaders_DisabledConfiguration_UsesNoForwardedHeaders()

Verifies that when AddApplicationForwardedHeaders is called with Enabled set to false, the ForwardedHeadersOptions are configured to use no forwarded headers regardless of any other configuration values provided. This ensures that the middleware will not process any forwarded headers when disabled, even if header names or other settings are specified in the configuration.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/ForwardedHeadersExtensionsCoverageTests.cs", 57)]
public void AddApplicationForwardedHeaders_DisabledConfiguration_UsesNoForwardedHeaders()

AddApplicationForwardedHeaders_EnabledConfiguration_ConfiguresForwardedHeadersOptions()

Verifies that AddApplicationForwardedHeaders correctly configures ForwardedHeadersOptions based on the provided configuration when enabled. This test covers the mapping of all relevant properties from ApplicationForwardedHeadersOptions to ForwardedHeadersOptions, as well as validation of header names and known proxies/networks.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/ForwardedHeadersExtensionsCoverageTests.cs", 17)]
public void AddApplicationForwardedHeaders_EnabledConfiguration_ConfiguresForwardedHeadersOptions()

AddApplicationForwardedHeaders_ForwardLimitZero_FailsOptionsValidation()

Verifies that when AddApplicationForwardedHeaders is called with a ForwardLimit of zero, the options validation fails with an appropriate error message. This test ensures that the ForwardLimit property is correctly validated to be either null or greater than zero, preventing misconfiguration that could lead to unexpected behavior in the middleware when processing forwarded headers.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/ForwardedHeadersExtensionsCoverageTests.cs", 112)]
public void AddApplicationForwardedHeaders_ForwardLimitZero_FailsOptionsValidation()

AddApplicationForwardedHeaders_ForwardedHostWithoutAllowedHosts_FailsOptionsValidation()

Verifies that when AddApplicationForwardedHeaders is called with XForwardedHost enabled in the Headers configuration but no allowed hosts specified in the AllowedHosts configuration, the options validation fails with an appropriate error message. This test ensures that the presence of XForwardedHost in the headers to process requires at least one allowed host to be configured, preventing misconfiguration that could lead to security issues or incorrect behavior in the middleware when processing forwarded host headers.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/ForwardedHeadersExtensionsCoverageTests.cs", 168)]
public void AddApplicationForwardedHeaders_ForwardedHostWithoutAllowedHosts_FailsOptionsValidation()

AddApplicationForwardedHeaders_HeaderNamesWithHyphensAndUnderscores_AreParsed()

Verifies that AddApplicationForwardedHeaders correctly parses header names with hyphens and underscores from the configuration and maps them to the appropriate ForwardedHeaders enum values. This test ensures that common variations in header naming conventions are supported and that the middleware will recognize headers like "X-Forwarded-For" and "X_Forwarded_Proto" regardless of formatting in the configuration.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/ForwardedHeadersExtensionsCoverageTests.cs", 84)]
public void AddApplicationForwardedHeaders_HeaderNamesWithHyphensAndUnderscores_AreParsed()

AddApplicationForwardedHeaders_InvalidHeader_FailsOptionsValidation()

Verifies that when AddApplicationForwardedHeaders is called with an invalid header name in the configuration, the options validation fails with an appropriate error message. This test ensures that only valid header names that correspond to the ForwardedHeaders enum are accepted, preventing misconfiguration that could lead to runtime errors or unexpected behavior in the middleware when processing forwarded headers.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/ForwardedHeadersExtensionsCoverageTests.cs", 126)]
public void AddApplicationForwardedHeaders_InvalidHeader_FailsOptionsValidation()

AddApplicationForwardedHeaders_InvalidKnownNetwork_FailsOptionsValidation()

Verifies that when AddApplicationForwardedHeaders is called with an invalid known network CIDR range in the configuration, the options validation fails with an appropriate error message. This test ensures that the KnownNetworks property is correctly validated to contain valid CIDR notation for IP networks, preventing misconfiguration that could lead to security issues or incorrect behavior in the middleware when determining trusted networks.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/ForwardedHeadersExtensionsCoverageTests.cs", 154)]
public void AddApplicationForwardedHeaders_InvalidKnownNetwork_FailsOptionsValidation()

AddApplicationForwardedHeaders_InvalidKnownProxy_FailsOptionsValidation()

Verifies that when AddApplicationForwardedHeaders is called with an invalid known proxy IP address in the configuration, the options validation fails with an appropriate error message. This test ensures that the KnownProxies property is correctly validated to contain valid IP addresses, preventing misconfiguration that could lead to security issues or incorrect behavior in the middleware when determining trusted proxies.

[Fact("/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/tests/ProjectTemplate.Web.Tests/ForwardedHeadersExtensionsCoverageTests.cs", 140)]
public void AddApplicationForwardedHeaders_InvalidKnownProxy_FailsOptionsValidation()