public void Authenticate_ShouldAddAuthorizationAsTextValueToRequest_OnHttpAuthorizationHeaderHandling() { // Arrange const string url = "https://no-query.string"; var client = new RestClient(url); var request = new RestRequest(); _authenticator.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader; // Act _authenticator.Authenticate(client, request); // Assert var authParameter = request.Parameters.Single(x => x.Name == KnownHeaders.Authorization); var value = (string)authParameter.Value; Assert.Contains("OAuth", value); Assert.Contains("realm=\"Realm\"", value); Assert.Contains("oauth_timestamp=", value); Assert.Contains("oauth_signature=\"ConsumerSecret", value); Assert.Contains("oauth_nonce=", value); Assert.Contains("oauth_consumer_key=\"ConsumerKey\"", value); Assert.Contains("oauth_signature_method=\"PLAINTEXT\"", value); Assert.Contains("oauth_version=\"Version\"", value); Assert.Contains("x_auth_mode=\"client_auth\"", value); Assert.Contains("x_auth_username=\"ClientUsername\"", value); Assert.Contains("x_auth_password=\"ClientPassword\"", value); }
public void Authenticate_ShouldAddAuthorizationAsTextValueToRequest_OnHttpAuthorizationHeaderHandling() { // Arrange var uri = new Uri("https://no-query.string"); mockClient.Setup(x => x.BuildUri(It.IsAny <IRestRequest>())).Returns(uri); authenticator.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader; // Act authenticator.Authenticate(mockClient.Object, mockRequest.Object); // Assert var authParameter = mockRequest.Object.Parameters.Single(x => x.Name == "Authorization"); var value = (string)authParameter.Value; Assert.IsTrue(value.Contains("OAuth")); Assert.IsTrue(value.Contains("realm=\"Realm\"")); Assert.IsTrue(value.Contains("oauth_timestamp=")); Assert.IsTrue(value.Contains("oauth_signature=\"ConsumerSecret")); Assert.IsTrue(value.Contains("oauth_nonce=")); Assert.IsTrue(value.Contains("oauth_consumer_key=\"ConsumerKey\"")); Assert.IsTrue(value.Contains("oauth_signature_method=\"PLAINTEXT\"")); Assert.IsTrue(value.Contains("oauth_version=\"Version\"")); Assert.IsTrue(value.Contains("x_auth_mode=\"client_auth\"")); Assert.IsTrue(value.Contains("x_auth_username=\"ClientUsername\"")); Assert.IsTrue(value.Contains("x_auth_password=\"ClientPassword\"")); }