Skip to content

Commit

Permalink
Merge pull request #96 from saliksaly/master
Browse files Browse the repository at this point in the history
Modify http multipart test to check proper non-ascii file name treating (fix #95)
  • Loading branch information
twitchax committed Jun 1, 2022
2 parents 275cc79 + 2d73e70 commit 700cbcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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

0 comments on commit 700cbcb

Please sign in to comment.