diff --git a/src/Http/Routing/test/UnitTests/Matching/HostMatcherPolicyIntegrationTestBase.cs b/src/Http/Routing/test/UnitTests/Matching/HostMatcherPolicyIntegrationTestBase.cs index e3cb4732b6..0e9d6da6c0 100644 --- a/src/Http/Routing/test/UnitTests/Matching/HostMatcherPolicyIntegrationTestBase.cs +++ b/src/Http/Routing/test/UnitTests/Matching/HostMatcherPolicyIntegrationTestBase.cs @@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Routing.Matching } [Fact] - public async Task Match_HostWithWildcard() + public async Task Match_HostWithWildcard_Unicode() { // Arrange var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*.contoso.com:8080", }); @@ -114,7 +114,23 @@ namespace Microsoft.AspNetCore.Routing.Matching } [Fact] - public async Task Match_HostWithWildcard_Unicode() + public async Task Match_HostWithWildcard_NoSubdomain() + { + // Arrange + var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*.contoso.com:8080", }); + + var matcher = CreateMatcher(endpoint); + var httpContext = CreateContext("/hello", "contoso.com:8080"); + + // Act + await matcher.MatchAsync(httpContext); + + // Assert + MatcherAssert.AssertNotMatch(httpContext); + } + + [Fact] + public async Task Match_HostWithWildcard_Subdomain() { // Arrange var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*.contoso.com:8080", }); @@ -129,6 +145,54 @@ namespace Microsoft.AspNetCore.Routing.Matching MatcherAssert.AssertMatch(httpContext, endpoint); } + [Fact] + public async Task Match_HostWithWildcard_MultipleSubdomains() + { + // Arrange + var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*.contoso.com:8080", }); + + var matcher = CreateMatcher(endpoint); + var httpContext = CreateContext("/hello", "www.blog.contoso.com:8080"); + + // Act + await matcher.MatchAsync(httpContext); + + // Assert + MatcherAssert.AssertMatch(httpContext, endpoint); + } + + [Fact] + public async Task Match_HostWithWildcard_PrefixNotInSubdomain() + { + // Arrange + var endpoint = CreateEndpoint("/hello", hosts: new string[] { "*.contoso.com:8080", }); + + var matcher = CreateMatcher(endpoint); + var httpContext = CreateContext("/hello", "mycontoso.com:8080"); + + // Act + await matcher.MatchAsync(httpContext); + + // Assert + MatcherAssert.AssertNotMatch(httpContext); + } + + [Fact] + public async Task Match_HostAndHostWithWildcard_NoSubdomain() + { + // Arrange + var endpoint = CreateEndpoint("/hello", hosts: new string[] { "contoso.com:8080", "*.contoso.com:8080", }); + + var matcher = CreateMatcher(endpoint); + var httpContext = CreateContext("/hello", "contoso.com:8080"); + + // Act + await matcher.MatchAsync(httpContext); + + // Assert + MatcherAssert.AssertMatch(httpContext, endpoint); + } + [Fact] public async Task Match_Host_CaseInsensitive() {