Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adds test for parameters encoding
  • Loading branch information
Eleonora Adova committed Sep 12, 2023
commit 6a30d676bb789d93c9fdd5886b44b1491f43d8e4
26 changes: 19 additions & 7 deletions test/RestSharp.Tests.Integrated/OAuth1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,29 @@ public async Task Can_Authenticate_OAuth1_With_Querystring_Parameters() {
actual.Should().BeEquivalentTo(expected);
}

[Fact]
public void Properly_Encodes_Parameter_Names() {
var postData = new WebPairCollection {
{ "name[first]", "Chuck" },
{ "name[last]", "Testa" }
};
[Theory]
[MemberData(nameof(EncodeParametersTestData))]
public void Properly_Encodes_Parameter_Names(IList<(string, string)> parameters, string expected) {
var postData = new WebPairCollection();
postData.AddRange(parameters.Select(x => new WebPair(x.Item1, x.Item2)));
var sortedParams = OAuthTools.SortParametersExcludingSignature(postData);

sortedParams.First().Should().Be("name%5Bfirst%5D=Chuck");
sortedParams.First().Should().Be(expected);
}

public static IEnumerable<object[]> EncodeParametersTestData =>
new List<object[]>
{
new object[] {
new List<(string, string)> { ("name[first]", "Chuck"), ("name[last]", "Testa") },
"name%5Bfirst%5D=Chuck"
},
new object[] {
new List<(string, string)> { ("country", "España") },
"country=Espa%C3%B1a"
}
};

[Fact]
public void Use_RFC_3986_Encoding_For_Auth_Signature_Base() {
// reserved characters for 2396 and 3986
Expand Down