From 2d73e70450a3cce23c6d5089386563218821b511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kal=C3=A1b?= Date: Thu, 26 May 2022 10:18:51 +0200 Subject: [PATCH] Modify http multipart test to check proper non-ascii file name treating --- src/Test/Http/HttpHelpers.cs | 2 +- src/Test/Http/HttpIntegrationTests.cs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Test/Http/HttpHelpers.cs b/src/Test/Http/HttpHelpers.cs index 7781e29..d20e3dd 100644 --- a/src/Test/Http/HttpHelpers.cs +++ b/src/Test/Http/HttpHelpers.cs @@ -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}")] diff --git a/src/Test/Http/HttpIntegrationTests.cs b/src/Test/Http/HttpIntegrationTests.cs index e716a98..6adbe42 100644 --- a/src/Test/Http/HttpIntegrationTests.cs +++ b/src/Test/Http/HttpIntegrationTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -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); @@ -93,7 +95,9 @@ public async Task CanProxyControllerPostWithFormAndFilesRequest() var files = Assert.IsAssignableFrom(json["files"]); Assert.Single(files); - Assert.Equal(fileString, files["testFile"]); + var file = files.ToObject>().Single(); + Assert.Equal($"data:application/octet-stream;base64,{Convert.ToBase64String(Encoding.UTF8.GetBytes(fileString))}", file.Value); + Assert.Equal(fileName, file.Key); } [Fact]