remove leading and trailing whitespace from the key

This commit is contained in:
cvium 2021-09-03 23:56:19 +02:00
parent 60185f99c4
commit 1172ece856
2 changed files with 54 additions and 7 deletions

View File

@ -291,7 +291,7 @@ namespace Jellyfin.Server.Implementations.Security
} }
else if (!escaped && token == '=') else if (!escaped && token == '=')
{ {
key = authorizationHeader[start.. i].ToString(); key = authorizationHeader[start.. i].Trim().ToString();
start = i + 1; start = i + 1;
} }
} }

View File

@ -52,14 +52,61 @@ namespace Jellyfin.Api.Tests.Auth.DefaultAuthorizationPolicy
} }
[Theory] [Theory]
[InlineData("x=\"123,123\",y=\"123\"", "x", "123,123")] [MemberData(nameof(GetParts_ValidAuthHeader_Success_Data))]
[InlineData("x=\"ab\"", "x", "ab")] public void GetParts_ValidAuthHeader_Success(string input, Dictionary<string, string> parts)
[InlineData("param=Hörbücher", "param", "Hörbücher")]
[InlineData("param=%22%Hörbücher", "param", "\"%Hörbücher")]
public void TestAuthHeaders(string input, string key, string value)
{ {
var dict = AuthorizationContext.GetParts(input); var dict = AuthorizationContext.GetParts(input);
Assert.True(string.Equals(dict[key], value, System.StringComparison.Ordinal)); foreach (var (key, value) in parts)
{
Assert.Equal(dict[key], value);
}
}
private static TheoryData<string, Dictionary<string, string>> GetParts_ValidAuthHeader_Success_Data()
{
var data = new TheoryData<string, Dictionary<string, string>>();
data.Add(
"x=\"123,123\",y=\"123\"",
new Dictionary<string, string>
{
{ "x", "123,123" },
{ "y", "123" }
});
data.Add(
"x=\"123,123\", y=\"123\",z=\"'hi'\"",
new Dictionary<string, string>
{
{ "x", "123,123" },
{ "y", "123" },
{ "z", "'hi'" }
});
data.Add(
"x=\"ab\"",
new Dictionary<string, string>
{
{ "x", "ab" }
});
data.Add(
"param=Hörbücher",
new Dictionary<string, string>
{
{ "param", "Hörbücher" }
}
);
data.Add(
"param=%22%Hörbücher",
new Dictionary<string, string>
{
{ "param", "\"%Hörbücher" }
}
);
return data;
} }
} }
} }