tests and small fix.

This commit is contained in:
BaronGreenback 2021-05-07 14:02:42 +01:00
parent c8061f92be
commit 4f5c9e9504
3 changed files with 62 additions and 2 deletions

View File

@ -84,13 +84,19 @@ namespace Jellyfin.Api.Controllers
/// <summary>
/// Pings the system.
/// </summary>
/// <param name="params">Optional: Parameters to echo back in the response.</param>
/// <response code="200">Information retrieved.</response>
/// <returns>The server name.</returns>
[HttpGet("Ping", Name = "GetPingSystem")]
[HttpPost("Ping", Name = "PostPingSystem")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<string> PingSystem()
public ActionResult<string> PingSystem([FromQuery]Dictionary<string, string>? @params = null)
{
if (@params != null && @params.Count > 0)
{
Response.Headers.Add("querystring", string.Join("&", @params.Select(x => x.Key + "=" + x.Value)));
}
return _appHost.Name;
}

View File

@ -66,7 +66,14 @@ namespace Jellyfin.Server.Middleware
foreach (var pair in queryString)
{
var item = pair.Split('=', System.StringSplitOptions.RemoveEmptyEntries);
pairs.Add(item[0], new StringValues(item.Length == 2 ? item[1] : string.Empty));
if (item.Length > 0)
{
pairs.Add(item[0], new StringValues(item.Length == 2 ? item[1] : string.Empty));
}
else
{
pairs.Add(pair, string.Empty);
}
}
_store = new QueryCollection(pairs);

View File

@ -0,0 +1,47 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Jellyfin.Api.Tests.Controllers
{
/// <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;
}
[Fact]
public async Task Ensure_Ping_Working()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("system/ping").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
[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("%3D", "==")] // will decode with an empty string value '=' = ''.
[InlineData("a%3D1%26b%3D2%26c%3D3", "a=1&b=2&c=3")] // will be processed.
public async Task Ensure_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
{
var client = _factory.CreateClient();
var response = await client.GetAsync("system/ping?" + sourceUrl).ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(unencodedUrl, response.Headers.GetValues("querystring").First());
}
}
}