aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Server.Integration.Tests/EncodedQueryStringTest.cs
blob: 2361e4aa4e60ed85b70c0b10958b2171ec0ed461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Net;
using System.Threading.Tasks;
using Xunit;

namespace Jellyfin.Server.Integration.Tests
{
    /// <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;
        }

        [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("a%3D1%26b%3D2%26c%3D3", "a=1&b=2&c=3")] // will be processed.
        [InlineData("a=b&a=c", "a=b")]
        [InlineData("a%3D1", "a=1")]
        [InlineData("a%3Db%26a%3Dc", "a=b")]
        public async Task Ensure_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
        {
            var client = _factory.CreateClient();

            var response = await client.GetAsync("Encoder/UrlDecode?" + sourceUrl).ConfigureAwait(false);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            string reply = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
            Assert.Equal(unencodedUrl, reply);
        }

        [Theory]
        [InlineData("a=b&a=c", "a=b,c")]
        [InlineData("a%3Db%26a%3Dc", "a=b,c")]
        public async Task Ensure_Array_Decoding_Of_Urls_Is_Working(string sourceUrl, string unencodedUrl)
        {
            var client = _factory.CreateClient();

            var response = await client.GetAsync("Encoder/UrlArrayDecode?" + sourceUrl).ConfigureAwait(false);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            string reply = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
            Assert.Equal(unencodedUrl, reply);
        }
    }
}