public DefaultOAuthAuthorizationPolicy(CredentialSet credentials) { _innerOauthPolicy = new OAuthAuthorizationPolicy( new MadgexOAuthHeader(new SystemClock(), new SystemNonceFactory()), credentials ); }
public void it_preserves_supplied_uri() { var request = Request.Get(new Uri("http://xxx?jazz=a%20fat%20tart")); var result = new OAuthAuthorizationPolicy(_oAuthHeaderProvider, AnyCredentials).Authorize(request); Assert.AreEqual(request.RequestLine.Uri, result.RequestLine.Uri, "Expected that the initial URI stay the same (implying query parameters are not parsed)" ); }
public void it_adds_an_oauth_header() { var request = Request.Get(new Uri("http://xxx")); var oAuthRequestAuthorizer = new OAuthAuthorizationPolicy(_oAuthHeaderProvider, AnyCredentials); var result = oAuthRequestAuthorizer.Authorize(request); Assert.That(result.Headers.Count, Is.GreaterThan(0)); }
public void it_fails_with_null_credentials() { var request = Request.Get(new Uri("http://xxx")); CredentialSet nullCredentials = null; var oAuthRequestAuthorizer = new OAuthAuthorizationPolicy(_oAuthHeaderProvider, nullCredentials); var theError = Assert.Throws<InvalidOperationException>(() => oAuthRequestAuthorizer.Authorize(request) ); Assert.AreEqual("Credentials are required.", theError.Message); }
public void you_can_use_oauth() { var authPolicy = new OAuthAuthorizationPolicy( new MadgexOAuthHeader( new SystemClock(), new SystemNonceFactory() ), Settings.Credentials ); var theInternetWithOAuth = new SystemInternet(authPolicy, new ConsoleLog()); var nodes = new Nodes(theInternetWithOAuth, Settings.BaseUrl); Assert.That(nodes.FindAll().Count, Is.GreaterThan(0), "Expected at least one making node to be returned."); }
public void if_you_supply_invalid_credentials_you_get_an_error() { var invalidCredentials = new CredentialSet(new Credential("xxx_clearly_invalid", "")); var authorizationPolicy = new OAuthAuthorizationPolicy( new MadgexOAuthHeader(new SystemClock(), new SystemNonceFactory()), invalidCredentials ); var theInternet = new SystemInternet(authorizationPolicy); var nodes = new Nodes(theInternet, Settings.BaseUrl); var theError = Assert.Throws<Exception>(() => nodes.FindAll()); Assert.That(theError.Message, Is.StringEnding("The server returned status Unauthorized (401), and error message: \"Invalid OAuth Request\"")); }
public void when_authorizing_a_get_it_leaves_parameters_in_uri_and_does_not_return_payload() { var uri = new Uri("http://xxx?Phil%20Murphy=Gluten-free%20anything&Jazz%20Kang&DIY%Kebab"); var request = Request.Get(uri); var result = new OAuthAuthorizationPolicy(_oAuthHeaderProvider, AnyCredentials).Authorize(request); Assert.AreEqual(uri, result.RequestLine.Uri); Assert.That(result.Payload, Is.Empty, "Expected no payload because the request was a GET"); }