33
44using System . Net ;
55using System . Net . Http ;
6- using System . Threading . Tasks ;
76using Microsoft . AspNetCore . Server . IIS . FunctionalTests . Utilities ;
87using Microsoft . AspNetCore . Server . IntegrationTesting ;
98using Microsoft . AspNetCore . Server . IntegrationTesting . IIS ;
109using Microsoft . AspNetCore . Testing ;
11- using Xunit ;
1210
1311#if ! IIS_FUNCTIONALS
1412using Microsoft . AspNetCore . Server . IIS . FunctionalTests ;
@@ -59,13 +57,14 @@ public async Task SetIISLimitMaxRequestBodySizeE2EWorks()
5957 . GetOrAdd ( "requestFiltering" )
6058 . GetOrAdd ( "requestLimits" , "maxAllowedContentLength" , "1" ) ;
6159 } ) ;
62- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
63-
64- var result = await deploymentResult . HttpClient . PostAsync ( "/ReadRequestBody" , new StringContent ( "test" ) ) ;
60+ await RunTest ( deploymentParameters , async deploymentResult =>
61+ {
62+ var result = await deploymentResult . HttpClient . PostAsync ( "/ReadRequestBody" , new StringContent ( "test" ) ) ;
6563
66- // IIS either returns a 404 or a 413 based on versions of IIS.
67- // Check for both as we don't know which specific patch version.
68- Assert . True ( result . StatusCode == HttpStatusCode . NotFound || result . StatusCode == HttpStatusCode . RequestEntityTooLarge ) ;
64+ // IIS either returns a 404 or a 413 based on versions of IIS.
65+ // Check for both as we don't know which specific patch version.
66+ Assert . True ( result . StatusCode == HttpStatusCode . NotFound || result . StatusCode == HttpStatusCode . RequestEntityTooLarge ) ;
67+ } ) ;
6968 }
7069
7170 [ ConditionalFact ]
@@ -82,11 +81,11 @@ public async Task SetIISLimitMaxRequestBodySizeE2EWorksWithLargerLimit()
8281 . GetOrAdd ( "requestFiltering" )
8382 . GetOrAdd ( "requestLimits" , "maxAllowedContentLength" , "100000000" ) ;
8483 } ) ;
85- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
86-
87- var result = await deploymentResult . HttpClient . PostAsync ( "/ReadRequestBodyLarger" , new StringContent ( new string ( 'a' , 100000000 ) ) ) ;
88-
89- Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
84+ await RunTest ( deploymentParameters , async deploymentResult =>
85+ {
86+ var result = await deploymentResult . HttpClient . PostAsync ( "/ReadRequestBodyLarger" , new StringContent ( new string ( 'a' , 100000000 ) ) ) ;
87+ Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
88+ } ) ;
9089 }
9190
9291 [ ConditionalFact ]
@@ -103,31 +102,32 @@ public async Task SetIISLimitMaxRequestBodySizeE2EWorksWithIntMaxValue()
103102 . GetOrAdd ( "requestFiltering" )
104103 . GetOrAdd ( "requestLimits" , "maxAllowedContentLength" , "4294967295" ) ;
105104 } ) ;
106- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
107-
108- var result = await deploymentResult . HttpClient . PostAsync ( "/ReadRequestBodyLarger" , new StringContent ( new string ( 'a' , 10000 ) ) ) ;
109-
110- Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
105+ await RunTest ( deploymentParameters , async deploymentResult =>
106+ {
107+ var result = await deploymentResult . HttpClient . PostAsync ( "/ReadRequestBodyLarger" , new StringContent ( new string ( 'a' , 10000 ) ) ) ;
108+ Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
109+ } ) ;
111110 }
112111
113112 [ ConditionalFact ]
114113 [ RequiresNewHandler ]
115114 public async Task IISRejectsContentLengthTooLargeByDefault ( )
116115 {
117116 var deploymentParameters = Fixture . GetBaseDeploymentParameters ( ) ;
118- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
119-
120- using ( var connection = new TestConnection ( deploymentResult . HttpClient . BaseAddress . Port ) )
117+ await RunTest ( deploymentParameters , async deploymentResult =>
121118 {
122- await connection . Send (
123- "POST /HelloWorld HTTP/1.1" ,
124- $ "Content-Length: 30000001",
125- "Host: localhost" ,
126- "" ,
127- "A" ) ;
128- var requestLine = await connection . ReadLineAsync ( ) ;
129- Assert . True ( requestLine . Contains ( "404" ) || requestLine . Contains ( "413" ) ) ;
130- }
119+ using ( var connection = new TestConnection ( deploymentResult . HttpClient . BaseAddress . Port ) )
120+ {
121+ await connection . Send (
122+ "POST /HelloWorld HTTP/1.1" ,
123+ $ "Content-Length: 30000001",
124+ "Host: localhost" ,
125+ "" ,
126+ "A" ) ;
127+ var requestLine = await connection . ReadLineAsync ( ) ;
128+ Assert . True ( requestLine . Contains ( "404" ) || requestLine . Contains ( "413" ) ) ;
129+ }
130+ } ) ;
131131 }
132132
133133 [ ConditionalFact ]
@@ -149,18 +149,19 @@ public async Task SetIISLimitMaxRequestBodyLogsWarning()
149149 . GetOrAdd ( "requestFiltering" )
150150 . GetOrAdd ( "requestLimits" , "maxAllowedContentLength" , "1" ) ;
151151 } ) ;
152- var deploymentResult = await DeployAsync ( deploymentParameters ) ;
153-
154- var result = await deploymentResult . HttpClient . PostAsync ( "/IncreaseRequestLimit" , new StringContent ( "1" ) ) ;
155- Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
152+ await RunTest ( deploymentParameters , async deploymentResult =>
153+ {
154+ var result = await deploymentResult . HttpClient . PostAsync ( "/IncreaseRequestLimit" , new StringContent ( "1" ) ) ;
155+ Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
156156
157- StopServer ( ) ;
157+ StopServer ( ) ;
158158
159- if ( deploymentParameters . ServerType == ServerType . IISExpress )
160- {
161- Assert . Single ( TestSink . Writes , w => w . Message . Contains ( "Increasing the MaxRequestBodySize conflicts with the max value for IIS limit maxAllowedContentLength." +
162- " HTTP requests that have a content length greater than maxAllowedContentLength will still be rejected by IIS." +
163- " You can disable the limit by either removing or setting the maxAllowedContentLength value to a higher limit." ) ) ;
164- }
159+ if ( deploymentParameters . ServerType == ServerType . IISExpress )
160+ {
161+ Assert . Single ( TestSink . Writes , w => w . Message . Contains ( "Increasing the MaxRequestBodySize conflicts with the max value for IIS limit maxAllowedContentLength." +
162+ " HTTP requests that have a content length greater than maxAllowedContentLength will still be rejected by IIS." +
163+ " You can disable the limit by either removing or setting the maxAllowedContentLength value to a higher limit." ) ) ;
164+ }
165+ } ) ;
165166 }
166167}
0 commit comments