Skip to content

Commit 9a41689

Browse files
Merge pull request restsharp#1167 from artiomchi/bugfix/oauth1-uri-query-handling
Query string shouldn't be removed in the OAuth1Authenticator
2 parents f90914d + a39f28e commit 9a41689

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

RestSharp.Tests/OAuth1AuthenticatorTests.cs

+24
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ public void Setup()
3636
mockClient.SetupGet(x => x.DefaultParameters).Returns(new List<Parameter>());
3737

3838
mockRequest = new Mock<RestRequest>();
39+
40+
mockWorkflow = new Mock<OAuthWorkflow>();
3941
}
4042

4143
private OAuth1Authenticator authenticator;
4244

4345
private Mock<RestRequest> mockRequest;
4446
private Mock<IRestClient> mockClient;
47+
private Mock<OAuthWorkflow> mockWorkflow;
4548

4649
[Test]
4750
public void Authenticate_ShouldAddAuthorizationAsTextValueToRequest_OnHttpAuthorizationHeaderHandling()
@@ -97,5 +100,26 @@ public void Authenticate_ShouldAddSignatureToRequestAsSeparateParameters_OnUrlOr
97100
Assert.IsNotNull(parameters.FirstOrDefault(x => x.Type == ParameterType.GetOrPost && x.Name == "oauth_nonce" && !string.IsNullOrWhiteSpace((string)x.Value) && x.ContentType == null));
98101
Assert.IsNotNull(parameters.FirstOrDefault(x => x.Type == ParameterType.GetOrPost && x.Name == "oauth_timestamp" && !string.IsNullOrWhiteSpace((string)x.Value) && x.ContentType == null));
99102
}
103+
104+
[Test]
105+
public void AddOAuthData_ProtectedResource_ShouldRetainQueryParamsFromUrl()
106+
{
107+
authenticator.Type = OAuthType.ProtectedResource;
108+
109+
var uri = new Uri("https://no-query.string?queryparameter=foobartemp");
110+
mockClient.Setup(x => x.BuildUri(It.IsAny<IRestRequest>())).Returns(uri);
111+
112+
var mockCall = mockWorkflow
113+
.Setup(x => x.BuildProtectedResourceInfo(It.IsAny<string>(), It.IsAny<WebParameterCollection>(), It.IsAny<string>()))
114+
.Callback<string, WebParameterCollection, string>((methodValue, webParamsValue, urlValue) =>
115+
{
116+
Assert.AreEqual(uri, urlValue);
117+
})
118+
.Returns(new OAuthWebQueryInfo());
119+
120+
mockClient.SetupGet(x => x.DefaultParameters).Returns(new List<Parameter>());
121+
122+
authenticator.AddOAuthData(mockClient.Object, mockRequest.Object, mockWorkflow.Object);
123+
}
100124
}
101125
}

RestSharp/AssemblyInfo.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
using System.Runtime.CompilerServices;
33

44
[assembly: InternalsVisibleTo("RestSharp.IntegrationTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fda57af14a288d46e3efea89617037585c4de57159cd536ca6dff792ea1d6addc665f2fccb4285413d9d44db5a1be87cb82686db200d16325ed9c42c89cd4824d8cc447f7cee2ac000924c3bceeb1b7fcb5cc1a3901785964d48ce14172001084134f4dcd9973c3776713b595443b1064bb53e2eeb924969244d354e46495e9d"),
5-
InternalsVisibleTo("RestSharp.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fda57af14a288d46e3efea89617037585c4de57159cd536ca6dff792ea1d6addc665f2fccb4285413d9d44db5a1be87cb82686db200d16325ed9c42c89cd4824d8cc447f7cee2ac000924c3bceeb1b7fcb5cc1a3901785964d48ce14172001084134f4dcd9973c3776713b595443b1064bb53e2eeb924969244d354e46495e9d")]
5+
InternalsVisibleTo("RestSharp.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fda57af14a288d46e3efea89617037585c4de57159cd536ca6dff792ea1d6addc665f2fccb4285413d9d44db5a1be87cb82686db200d16325ed9c42c89cd4824d8cc447f7cee2ac000924c3bceeb1b7fcb5cc1a3901785964d48ce14172001084134f4dcd9973c3776713b595443b1064bb53e2eeb924969244d354e46495e9d"),
6+
InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
67
[assembly: CLSCompliant(true)]

RestSharp/Authenticators/OAuth1Authenticator.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// distributed under the License is distributed on an "AS IS" BASIS,
1313
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
// See the License for the specific language governing permissions and
15-
// limitations under the License.
15+
// limitations under the License.
1616

1717
#endregion
1818

@@ -191,14 +191,10 @@ public static OAuth1Authenticator ForProtectedResource(string consumerKey, strin
191191
return authenticator;
192192
}
193193

194-
private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflow workflow)
194+
internal void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflow workflow)
195195
{
196196
var url = client.BuildUri(request)
197197
.ToString();
198-
var queryStringStart = url.IndexOf('?');
199-
200-
if (queryStringStart != -1)
201-
url = url.Substring(0, queryStringStart);
202198

203199
OAuthWebQueryInfo oauth;
204200
var method = request.Method.ToString()

0 commit comments

Comments
 (0)