EncodedQueryStringTest.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Net;
  2. using System.Threading.Tasks;
  3. using Xunit;
  4. namespace Jellyfin.Server.Integration.Tests
  5. {
  6. /// <summary>
  7. /// Defines the test for encoded querystrings in the url.
  8. /// </summary>
  9. public class EncodedQueryStringTest : IClassFixture<JellyfinApplicationFactory>
  10. {
  11. private readonly JellyfinApplicationFactory _factory;
  12. public EncodedQueryStringTest(JellyfinApplicationFactory factory)
  13. {
  14. _factory = factory;
  15. }
  16. [Theory]
  17. [InlineData("a=1&b=2&c=3", "a=1&b=2&c=3")] // won't be processed as there is more than 1.
  18. [InlineData("a=1", "a=1")] // won't be processed as it has a value
  19. [InlineData("a%3D1%26b%3D2%26c%3D3", "a=1&b=2&c=3")] // will be processed.
  20. [InlineData("a=b&a=c", "a=b")]
  21. [InlineData("a%3D1", "a=1")]
  22. [InlineData("a%3Db%26a%3Dc", "a=b")]
  23. public async Task Ensure_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
  24. {
  25. var client = _factory.CreateClient();
  26. var response = await client.GetAsync("Encoder/UrlDecode?" + sourceUrl);
  27. Assert.Equal(HttpStatusCode.OK, response.StatusCode);
  28. string reply = await response.Content.ReadAsStringAsync();
  29. Assert.Equal(unencodedUrl, reply);
  30. }
  31. [Theory]
  32. [InlineData("a=b&a=c", "a=b,c")]
  33. [InlineData("a%3Db%26a%3Dc", "a=b,c")]
  34. public async Task Ensure_Array_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
  35. {
  36. var client = _factory.CreateClient();
  37. var response = await client.GetAsync("Encoder/UrlArrayDecode?" + sourceUrl);
  38. Assert.Equal(HttpStatusCode.OK, response.StatusCode);
  39. string reply = await response.Content.ReadAsStringAsync();
  40. Assert.Equal(unencodedUrl, reply);
  41. }
  42. }
  43. }