2
0

EncodedQueryStringTest.cs 1.6 KB

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