EncodedQueryStringTest.cs 1.4 KB

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