EncodedQueryStringTest.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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%3Db%26a%3Dc", "a=b")]
  22. public async Task Ensure_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
  23. {
  24. var client = _factory.CreateClient();
  25. var response = await client.GetAsync("Encoder/UrlDecode?" + sourceUrl).ConfigureAwait(false);
  26. Assert.Equal(HttpStatusCode.OK, response.StatusCode);
  27. string reply = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
  28. Assert.Equal(unencodedUrl, reply);
  29. }
  30. [Theory]
  31. [InlineData("a=b&a=c", "a=b,c")]
  32. [InlineData("a%3Db%26a%3Dc", "a=b,c")]
  33. public async Task Ensure_Array_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
  34. {
  35. var client = _factory.CreateClient();
  36. var response = await client.GetAsync("Encoder/UrlArrayDecode?" + sourceUrl).ConfigureAwait(false);
  37. Assert.Equal(HttpStatusCode.OK, response.StatusCode);
  38. string reply = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
  39. Assert.Equal(unencodedUrl, reply);
  40. }
  41. }
  42. }