@@ -4479,18 +4479,19 @@ void TestAction(IFormFileCollection formFiles, IFormFile file)
4479
4479
}
4480
4480
4481
4481
[ Theory ]
4482
- [ InlineData ( "Authorization" , "bearer my-token" , "Support for binding parameters from an HTTP request's form is not currently supported if the request contains an \" Authorization \" HTTP request header. Use of an HTTP request form is not currently secure for HTTP requests in scenarios which require authentication." ) ]
4483
- [ InlineData ( "Cookie" , ".AspNetCore.Auth=abc123" , "Support for binding parameters from an HTTP request's form is not currently supported if the request contains a \" Cookie \" HTTP request header. Use of an HTTP request form is not currently secure for HTTP requests in scenarios which require authentication." ) ]
4484
- public async Task RequestDelegateThrowsIfRequestUsingFormContainsSecureHeader (
4482
+ [ InlineData ( "Authorization" , "bearer my-token" ) ]
4483
+ [ InlineData ( "Cookie" , ".AspNetCore.Auth=abc123" ) ]
4484
+ public async Task RequestDelegatePopulatesFromIFormFileParameterIfRequestContainsSecureHeader (
4485
4485
string headerName ,
4486
- string headerValue ,
4487
- string expectedMessage )
4486
+ string headerValue )
4488
4487
{
4489
- var invoked = false ;
4488
+ IFormFile ? fileArgument = null ;
4489
+ TraceIdentifier traceIdArgument = default ;
4490
4490
4491
- void TestAction ( IFormFile file )
4491
+ void TestAction ( IFormFile ? file , TraceIdentifier traceId )
4492
4492
{
4493
- invoked = true ;
4493
+ fileArgument = file ;
4494
+ traceIdArgument = traceId ;
4494
4495
}
4495
4496
4496
4497
var fileContent = new StringContent ( "hello" , Encoding . UTF8 , "application/octet-stream" ) ;
@@ -4507,34 +4508,30 @@ void TestAction(IFormFile file)
4507
4508
httpContext . Request . Headers [ headerName ] = headerValue ;
4508
4509
httpContext . Request . Headers [ "Content-Type" ] = "multipart/form-data;boundary=some-boundary" ;
4509
4510
httpContext . Features . Set < IHttpRequestBodyDetectionFeature > ( new RequestBodyDetectionFeature ( true ) ) ;
4511
+ httpContext . TraceIdentifier = "my-trace-id" ;
4510
4512
4511
4513
var factoryResult = RequestDelegateFactory . Create ( TestAction ) ;
4512
4514
var requestDelegate = factoryResult . RequestDelegate ;
4513
4515
4514
- var badHttpRequestException = await Assert . ThrowsAsync < BadHttpRequestException > ( ( ) => requestDelegate ( httpContext ) ) ;
4515
-
4516
- Assert . False ( invoked ) ;
4517
-
4518
- // The httpContext should be untouched.
4519
- Assert . False ( httpContext . RequestAborted . IsCancellationRequested ) ;
4520
- Assert . Equal ( 200 , httpContext . Response . StatusCode ) ;
4521
- Assert . False ( httpContext . Response . HasStarted ) ;
4516
+ await requestDelegate ( httpContext ) ;
4522
4517
4523
- // We don't log bad requests when we throw.
4524
- Assert . Empty ( TestSink . Writes ) ;
4518
+ Assert . Equal ( httpContext . Request . Form . Files [ "file" ] , fileArgument ) ;
4519
+ Assert . Equal ( "file.txt" , fileArgument ! . FileName ) ;
4520
+ Assert . Equal ( "file" , fileArgument . Name ) ;
4525
4521
4526
- Assert . Equal ( expectedMessage , badHttpRequestException . Message ) ;
4527
- Assert . Equal ( 400 , badHttpRequestException . StatusCode ) ;
4522
+ Assert . Equal ( "my-trace-id" , traceIdArgument . Id ) ;
4528
4523
}
4529
4524
4530
4525
[ Fact ]
4531
- public async Task RequestDelegateThrowsIfRequestUsingFormHasClientCertificate ( )
4526
+ public async Task RequestDelegatePopulatesFromIFormFileParameterIfRequestHasClientCertificate ( )
4532
4527
{
4533
- var invoked = false ;
4528
+ IFormFile ? fileArgument = null ;
4529
+ TraceIdentifier traceIdArgument = default ;
4534
4530
4535
- void TestAction ( IFormFile file )
4531
+ void TestAction ( IFormFile ? file , TraceIdentifier traceId )
4536
4532
{
4537
- invoked = true ;
4533
+ fileArgument = file ;
4534
+ traceIdArgument = traceId ;
4538
4535
}
4539
4536
4540
4537
var fileContent = new StringContent ( "hello" , Encoding . UTF8 , "application/octet-stream" ) ;
@@ -4550,6 +4547,7 @@ void TestAction(IFormFile file)
4550
4547
httpContext . Request . Body = stream ;
4551
4548
httpContext . Request . Headers [ "Content-Type" ] = "multipart/form-data;boundary=some-boundary" ;
4552
4549
httpContext . Features . Set < IHttpRequestBodyDetectionFeature > ( new RequestBodyDetectionFeature ( true ) ) ;
4550
+ httpContext . TraceIdentifier = "my-trace-id" ;
4553
4551
4554
4552
#pragma warning disable SYSLIB0026 // Type or member is obsolete
4555
4553
var clientCertificate = new X509Certificate2 ( ) ;
@@ -4560,20 +4558,13 @@ void TestAction(IFormFile file)
4560
4558
var factoryResult = RequestDelegateFactory . Create ( TestAction ) ;
4561
4559
var requestDelegate = factoryResult . RequestDelegate ;
4562
4560
4563
- var badHttpRequestException = await Assert . ThrowsAsync < BadHttpRequestException > ( ( ) => requestDelegate ( httpContext ) ) ;
4564
-
4565
- Assert . False ( invoked ) ;
4566
-
4567
- // The httpContext should be untouched.
4568
- Assert . False ( httpContext . RequestAborted . IsCancellationRequested ) ;
4569
- Assert . Equal ( 200 , httpContext . Response . StatusCode ) ;
4570
- Assert . False ( httpContext . Response . HasStarted ) ;
4561
+ await requestDelegate ( httpContext ) ;
4571
4562
4572
- // We don't log bad requests when we throw.
4573
- Assert . Empty ( TestSink . Writes ) ;
4563
+ Assert . Equal ( httpContext . Request . Form . Files [ "file" ] , fileArgument ) ;
4564
+ Assert . Equal ( "file.txt" , fileArgument ! . FileName ) ;
4565
+ Assert . Equal ( "file" , fileArgument . Name ) ;
4574
4566
4575
- Assert . Equal ( "Support for binding parameters from an HTTP request's form is not currently supported if the request is associated with a client certificate. Use of an HTTP request form is not currently secure for HTTP requests in scenarios which require authentication." , badHttpRequestException . Message ) ;
4576
- Assert . Equal ( 400 , badHttpRequestException . StatusCode ) ;
4567
+ Assert . Equal ( "my-trace-id" , traceIdArgument . Id ) ;
4577
4568
}
4578
4569
4579
4570
private record struct ParameterListRecordStruct ( HttpContext HttpContext , [ FromRoute ] int Value ) ;
0 commit comments