From 78b9b2e23e7709cef6659b11e7e0b266f7a1089f Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 31 Oct 2019 13:26:42 +1300 Subject: [PATCH] Additional host matching tests (#16680) --- .../HostMatcherPolicyIntegrationTestBase.cs | 68 ++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) 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() {