Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify http multipart test to check proper non-ascii file name treating (fix #95) #96

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Test/Http/HttpHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Task ProxyPostRequest()
[Route("api/multipart")]
public Task ProxyPostMultipartRequest()
{
return this.HttpProxyAsync("https://httpbin.org/post");
return this.HttpProxyAsync("https://postman-echo.com/post");
}

[Route("api/catchall/{**rest}")]
Expand Down
12 changes: 8 additions & 4 deletions src/Test/Http/HttpIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -74,12 +75,13 @@ public async Task CanProxyControllerPostWithFormAndFilesRequest()
content.Add(new StringContent("123"), "xyz");
content.Add(new StringContent("456"), "xyz");
content.Add(new StringContent("321"), "abc");
const string fileString = "This is a test file.";
const string fileName = "Test こんにちは file.txt";
const string fileString = "This is a test file こんにちは with non-ascii content.";
var fileContent = new StreamContent(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(fileString)));
content.Add(fileContent, "testFile", "Test file.txt");
content.Add(fileContent, "testFile", fileName);

var response = await _client.PostAsync("api/multipart", content);
response.EnsureSuccessStatusCode();

var responseString = await response.Content.ReadAsStringAsync();
var json = JObject.Parse(responseString);

Expand All @@ -93,7 +95,9 @@ public async Task CanProxyControllerPostWithFormAndFilesRequest()

var files = Assert.IsAssignableFrom<JObject>(json["files"]);
Assert.Single(files);
Assert.Equal(fileString, files["testFile"]);
var file = files.ToObject<Dictionary<string, string>>().Single();
Assert.Equal($"data:application/octet-stream;base64,{Convert.ToBase64String(Encoding.UTF8.GetBytes(fileString))}", file.Value);
Assert.Equal(fileName, file.Key);
}

[Fact]
Expand Down