Adds FormFeature quoted boundary test
This commit is contained in:
parent
637b57a8ae
commit
5ec8a7134e
|
|
@ -49,11 +49,15 @@ namespace Microsoft.AspNetCore.Http.Features
|
||||||
|
|
||||||
private const string MultipartContentType = "multipart/form-data; boundary=WebKitFormBoundary5pDRpGheQXaM8k3T";
|
private const string MultipartContentType = "multipart/form-data; boundary=WebKitFormBoundary5pDRpGheQXaM8k3T";
|
||||||
|
|
||||||
|
private const string MultipartContentTypeWithSpecialCharacters = "multipart/form-data; boundary=\"WebKitFormBoundary/:5pDRpGheQXaM8k3T\"";
|
||||||
|
|
||||||
private const string EmptyMultipartForm = "--WebKitFormBoundary5pDRpGheQXaM8k3T--";
|
private const string EmptyMultipartForm = "--WebKitFormBoundary5pDRpGheQXaM8k3T--";
|
||||||
|
|
||||||
// Note that CRLF (\r\n) is required. You can't use multi-line C# strings here because the line breaks on Linux are just LF.
|
// Note that CRLF (\r\n) is required. You can't use multi-line C# strings here because the line breaks on Linux are just LF.
|
||||||
private const string MultipartFormEnd = "--WebKitFormBoundary5pDRpGheQXaM8k3T--\r\n";
|
private const string MultipartFormEnd = "--WebKitFormBoundary5pDRpGheQXaM8k3T--\r\n";
|
||||||
|
|
||||||
|
private const string MultipartFormEndWithSpecialCharacters = "--WebKitFormBoundary/:5pDRpGheQXaM8k3T--\r\n";
|
||||||
|
|
||||||
private const string MultipartFormField = "--WebKitFormBoundary5pDRpGheQXaM8k3T\r\n" +
|
private const string MultipartFormField = "--WebKitFormBoundary5pDRpGheQXaM8k3T\r\n" +
|
||||||
"Content-Disposition: form-data; name=\"description\"\r\n" +
|
"Content-Disposition: form-data; name=\"description\"\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
|
|
@ -71,6 +75,12 @@ namespace Microsoft.AspNetCore.Http.Features
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"<html><body>Hello World</body></html>\r\n";
|
"<html><body>Hello World</body></html>\r\n";
|
||||||
|
|
||||||
|
private const string MultipartFormFileSpecialCharacters = "--WebKitFormBoundary/:5pDRpGheQXaM8k3T\r\n" +
|
||||||
|
"Content-Disposition: form-data; name=\"description\"\r\n" +
|
||||||
|
"\r\n" +
|
||||||
|
"Foo\r\n";
|
||||||
|
|
||||||
|
|
||||||
private const string MultipartFormWithField =
|
private const string MultipartFormWithField =
|
||||||
MultipartFormField +
|
MultipartFormField +
|
||||||
MultipartFormEnd;
|
MultipartFormEnd;
|
||||||
|
|
@ -88,6 +98,10 @@ namespace Microsoft.AspNetCore.Http.Features
|
||||||
MultipartFormEncodedFilename +
|
MultipartFormEncodedFilename +
|
||||||
MultipartFormEnd;
|
MultipartFormEnd;
|
||||||
|
|
||||||
|
private const string MultipartFormWithSpecialCharacters =
|
||||||
|
MultipartFormFileSpecialCharacters +
|
||||||
|
MultipartFormEndWithSpecialCharacters;
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(true)]
|
[InlineData(true)]
|
||||||
[InlineData(false)]
|
[InlineData(false)]
|
||||||
|
|
@ -208,6 +222,43 @@ namespace Microsoft.AspNetCore.Http.Features
|
||||||
await responseFeature.CompleteAsync();
|
await responseFeature.CompleteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(true)]
|
||||||
|
[InlineData(false)]
|
||||||
|
public async Task ReadFormAsync_MultipartWithFileAndQuotedBoundaryString_ReturnsParsedFormCollection(bool bufferRequest)
|
||||||
|
{
|
||||||
|
var formContent = Encoding.UTF8.GetBytes(MultipartFormWithSpecialCharacters);
|
||||||
|
var context = new DefaultHttpContext();
|
||||||
|
var responseFeature = new FakeResponseFeature();
|
||||||
|
context.Features.Set<IHttpResponseFeature>(responseFeature);
|
||||||
|
context.Request.ContentType = MultipartContentTypeWithSpecialCharacters;
|
||||||
|
context.Request.Body = new NonSeekableReadStream(formContent);
|
||||||
|
|
||||||
|
IFormFeature formFeature = new FormFeature(context.Request, new FormOptions() { BufferBody = bufferRequest });
|
||||||
|
context.Features.Set<IFormFeature>(formFeature);
|
||||||
|
|
||||||
|
var formCollection = context.Request.Form;
|
||||||
|
|
||||||
|
Assert.NotNull(formCollection);
|
||||||
|
|
||||||
|
// Cached
|
||||||
|
formFeature = context.Features.Get<IFormFeature>();
|
||||||
|
Assert.NotNull(formFeature);
|
||||||
|
Assert.NotNull(formFeature.Form);
|
||||||
|
Assert.Same(formCollection, formFeature.Form);
|
||||||
|
Assert.Same(formCollection, await context.Request.ReadFormAsync());
|
||||||
|
|
||||||
|
// Content
|
||||||
|
Assert.Equal(1, formCollection.Count);
|
||||||
|
Assert.Equal("Foo", formCollection["description"]);
|
||||||
|
|
||||||
|
Assert.NotNull(formCollection.Files);
|
||||||
|
Assert.Equal(0, formCollection.Files.Count);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
await responseFeature.CompleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(true)]
|
[InlineData(true)]
|
||||||
[InlineData(false)]
|
[InlineData(false)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue