jellyfin/tests/Jellyfin.Server.Integration.Tests/EncodedQueryStringTest.cs

50 lines
1.9 KiB
C#
Raw Normal View History

2021-05-07 15:02:42 +02:00
using System.Net;
using System.Threading.Tasks;
using Xunit;
2021-05-08 14:33:47 +02:00
namespace Jellyfin.Server.Integration.Tests
2021-05-07 15:02:42 +02:00
{
/// <summary>
/// Defines the test for encoded querystrings in the url.
/// </summary>
public class EncodedQueryStringTest : IClassFixture<JellyfinApplicationFactory>
{
private readonly JellyfinApplicationFactory _factory;
public EncodedQueryStringTest(JellyfinApplicationFactory factory)
{
_factory = factory;
}
[Theory]
[InlineData("a=1&b=2&c=3", "a=1&b=2&c=3")] // won't be processed as there is more than 1.
[InlineData("a=1", "a=1")] // won't be processed as it has a value
[InlineData("a%3D1%26b%3D2%26c%3D3", "a=1&b=2&c=3")] // will be processed.
[InlineData("a=b&a=c", "a=b")]
2021-09-25 18:15:46 +02:00
[InlineData("a%3D1", "a=1")]
[InlineData("a%3Db%26a%3Dc", "a=b")]
2021-05-07 15:02:42 +02:00
public async Task Ensure_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
{
var client = _factory.CreateClient();
2021-05-15 21:24:41 +02:00
var response = await client.GetAsync("Encoder/UrlDecode?" + sourceUrl).ConfigureAwait(false);
2021-05-07 15:02:42 +02:00
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
2021-05-07 21:11:32 +02:00
string reply = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Assert.Equal(unencodedUrl, reply);
2021-05-07 15:02:42 +02:00
}
[Theory]
[InlineData("a=b&a=c", "a=b,c")]
[InlineData("a%3Db%26a%3Dc", "a=b,c")]
public async Task Ensure_Array_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
{
var client = _factory.CreateClient();
var response = await client.GetAsync("Encoder/UrlArrayDecode?" + sourceUrl).ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string reply = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Assert.Equal(unencodedUrl, reply);
}
2021-05-07 15:02:42 +02:00
}
}