#246 Fix multipart test on linux.

This commit is contained in:
Chris Ross 2015-04-06 11:25:26 -07:00
parent 1f127d25c3
commit c24a40517f
2 changed files with 90 additions and 95 deletions

View File

@ -96,31 +96,32 @@ namespace Microsoft.AspNet.Http.Core
private const string MultipartContentType = "multipart/form-data; boundary=WebKitFormBoundary5pDRpGheQXaM8k3T"; private const string MultipartContentType = "multipart/form-data; boundary=WebKitFormBoundary5pDRpGheQXaM8k3T";
private const string EmptyMultipartForm = private const string EmptyMultipartForm =
@"--WebKitFormBoundary5pDRpGheQXaM8k3T--"; "--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.
private const string MultipartFormWithField = private const string MultipartFormWithField =
@"--WebKitFormBoundary5pDRpGheQXaM8k3T "--WebKitFormBoundary5pDRpGheQXaM8k3T\r\n" +
Content-Disposition: form-data; name=""description"" "Content-Disposition: form-data; name=\"description\"\r\n" +
"\r\n" +
Foo "Foo\r\n" +
--WebKitFormBoundary5pDRpGheQXaM8k3T--"; "--WebKitFormBoundary5pDRpGheQXaM8k3T--";
private const string MultipartFormWithFile = private const string MultipartFormWithFile =
@"--WebKitFormBoundary5pDRpGheQXaM8k3T "--WebKitFormBoundary5pDRpGheQXaM8k3T\r\n" +
Content-Disposition: form-data; name=""myfile1""; filename=""temp.html"" "Content-Disposition: form-data; name=\"myfile1\"; filename=\"temp.html\"\r\n" +
Content-Type: text/html "Content-Type: text/html\r\n" +
"\r\n" +
<html><body>Hello World</body></html> "<html><body>Hello World</body></html>\r\n" +
--WebKitFormBoundary5pDRpGheQXaM8k3T--"; "--WebKitFormBoundary5pDRpGheQXaM8k3T--";
private const string MultipartFormWithFieldAndFile = private const string MultipartFormWithFieldAndFile =
@"--WebKitFormBoundary5pDRpGheQXaM8k3T "--WebKitFormBoundary5pDRpGheQXaM8k3T\r\n" +
Content-Disposition: form-data; name=""description"" "Content-Disposition: form-data; name=\"description\"\r\n" +
"\r\n" +
Foo "Foo\r\n" +
--WebKitFormBoundary5pDRpGheQXaM8k3T "--WebKitFormBoundary5pDRpGheQXaM8k3T\r\n" +
Content-Disposition: form-data; name=""myfile1""; filename=""temp.html"" "Content-Disposition: form-data; name=\"myfile1\"; filename=\"temp.html\"\r\n" +
Content-Type: text/html "Content-Type: text/html\r\n" +
"\r\n" +
<html><body>Hello World</body></html> "<html><body>Hello World</body></html>\r\n" +
--WebKitFormBoundary5pDRpGheQXaM8k3T--"; "--WebKitFormBoundary5pDRpGheQXaM8k3T--";
[Fact] [Fact]
public async Task ReadForm_EmptyMultipart_ReturnsParsedFormCollection() public async Task ReadForm_EmptyMultipart_ReturnsParsedFormCollection()

View File

@ -11,72 +11,68 @@ namespace Microsoft.AspNet.WebUtilities
public class MultipartReaderTests public class MultipartReaderTests
{ {
private const string Boundary = "9051914041544843365972754266"; private const string Boundary = "9051914041544843365972754266";
// 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 OnePartBody = private const string OnePartBody =
@"--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""text"" "Content-Disposition: form-data; name=\"text\"\r\n" +
"\r\n" +
text default "text default\r\n" +
--9051914041544843365972754266-- "--9051914041544843365972754266--\r\n";
";
private const string OnePartBodyWithTrailingWhitespace = private const string OnePartBodyWithTrailingWhitespace =
@"--9051914041544843365972754266 "--9051914041544843365972754266 \r\n" +
Content-Disposition: form-data; name=""text"" "Content-Disposition: form-data; name=\"text\"\r\n" +
"\r\n" +
text default "text default\r\n" +
--9051914041544843365972754266-- "--9051914041544843365972754266--\r\n";
";
// It's non-compliant but common to leave off the last CRLF. // It's non-compliant but common to leave off the last CRLF.
private const string OnePartBodyWithoutFinalCRLF = private const string OnePartBodyWithoutFinalCRLF =
@"--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""text"" "Content-Disposition: form-data; name=\"text\"\r\n" +
"\r\n" +
text default "text default\r\n" +
--9051914041544843365972754266--"; "--9051914041544843365972754266--";
private const string TwoPartBody = private const string TwoPartBody =
@"--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""text"" "Content-Disposition: form-data; name=\"text\"\r\n" +
"\r\n" +
text default "text default\r\n" +
--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""file1""; filename=""a.txt"" "Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"\r\n" +
Content-Type: text/plain "Content-Type: text/plain\r\n" +
"\r\n" +
Content of a.txt. "Content of a.txt.\r\n" +
"\r\n" +
--9051914041544843365972754266-- "--9051914041544843365972754266--\r\n";
";
private const string TwoPartBodyWithUnicodeFileName = private const string TwoPartBodyWithUnicodeFileName =
@"--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""text"" "Content-Disposition: form-data; name=\"text\"\r\n" +
"\r\n" +
text default "text default\r\n" +
--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""file1""; filename=""a色.txt"" "Content-Disposition: form-data; name=\"file1\"; filename=\"a色.txt\"\r\n" +
Content-Type: text/plain "Content-Type: text/plain\r\n" +
"\r\n" +
Content of a.txt. "Content of a.txt.\r\n" +
"\r\n" +
--9051914041544843365972754266-- "--9051914041544843365972754266--\r\n";
";
private const string ThreePartBody = private const string ThreePartBody =
@"--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""text"" "Content-Disposition: form-data; name=\"text\"\r\n" +
"\r\n" +
text default "text default\r\n" +
--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""file1""; filename=""a.txt"" "Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"\r\n" +
Content-Type: text/plain "Content-Type: text/plain\r\n" +
"\r\n" +
Content of a.txt. "Content of a.txt.\r\n" +
"\r\n" +
--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""file2""; filename=""a.html"" "Content-Disposition: form-data; name=\"file2\"; filename=\"a.html\"\r\n" +
Content-Type: text/html "Content-Type: text/html\r\n" +
"\r\n" +
<!DOCTYPE html><title>Content of a.html.</title> "<!DOCTYPE html><title>Content of a.html.</title>\r\n" +
"\r\n" +
--9051914041544843365972754266-- "--9051914041544843365972754266--\r\n";
";
private static MemoryStream MakeStream(string text) private static MemoryStream MakeStream(string text)
{ {
@ -225,15 +221,14 @@ Content-Type: text/html
public async Task MutipartReader_ReadInvalidUtf8Header_ReplacementCharacters() public async Task MutipartReader_ReadInvalidUtf8Header_ReplacementCharacters()
{ {
var body1 = var body1 =
@"--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""text"" filename=""a"; "Content-Disposition: form-data; name=\"text\" filename=\"a";
var body2 = var body2 =
@".txt"" ".txt\"\r\n" +
"\r\n" +
text default "text default\r\n" +
--9051914041544843365972754266-- "--9051914041544843365972754266--\r\n";
";
var stream = new MemoryStream(); var stream = new MemoryStream();
var bytes = Encoding.UTF8.GetBytes(body1); var bytes = Encoding.UTF8.GetBytes(body1);
stream.Write(bytes, 0, bytes.Length); stream.Write(bytes, 0, bytes.Length);
@ -261,15 +256,14 @@ text default
public async Task MutipartReader_ReadInvalidUtf8SurrogateHeader_ReplacementCharacters() public async Task MutipartReader_ReadInvalidUtf8SurrogateHeader_ReplacementCharacters()
{ {
var body1 = var body1 =
@"--9051914041544843365972754266 "--9051914041544843365972754266\r\n" +
Content-Disposition: form-data; name=""text"" filename=""a"; "Content-Disposition: form-data; name=\"text\" filename=\"a";
var body2 = var body2 =
@".txt"" ".txt\"\r\n" +
"\r\n" +
text default "text default\r\n" +
--9051914041544843365972754266-- "--9051914041544843365972754266--\r\n";
";
var stream = new MemoryStream(); var stream = new MemoryStream();
var bytes = Encoding.UTF8.GetBytes(body1); var bytes = Encoding.UTF8.GetBytes(body1);
stream.Write(bytes, 0, bytes.Length); stream.Write(bytes, 0, bytes.Length);