public void you_can_use_simple_key_authorization() { var authPolicy = new SimpleKeyAuthorizationPolicy(Settings.SimpleKeyAuthorizationCredential); var theInternetWithSimpleKeyAuthorization = new SystemInternet(authPolicy, new ConsoleLog()); var nodes = new Nodes(theInternetWithSimpleKeyAuthorization, Settings.BaseUrl); Assert.That(nodes.FindAll().Count, Is.GreaterThan(0), "Expected at least one making node to be returned."); }
public void it_preserves_the_path() { var simpleKeyAuthorizer = new SimpleKeyAuthorizationPolicy( new SimpleKeyAuthorizationCredential("abcdefgh", "stuvwxyz") ); var request = new Request(RequestLine.Get(new Uri("http://xxx/yyy/zzz"))); var authorized = simpleKeyAuthorizer.Authorize(request); Assert.AreEqual(request.RequestLine.Uri.AbsolutePath, authorized.RequestLine.Uri.AbsolutePath); }
public void it_adds_the_app_key_and_user_access_key_to_the_url() { var simpleKeyAuthorizer = new SimpleKeyAuthorizationPolicy( new SimpleKeyAuthorizationCredential("abcdefgh", "stuvwxyz") ); var request = new Request(RequestLine.Get(new Uri("http://xxx/"))); var authorized = simpleKeyAuthorizer.Authorize(request); var expected = new Uri("http://xxx/?app_key=abcdefgh&user_access_key=stuvwxyz"); Assert.AreEqual(expected, authorized.RequestLine.Uri); }
public void it_preserves_other_params() { var simpleKeyAuthorizer = new SimpleKeyAuthorizationPolicy( new SimpleKeyAuthorizationCredential("abcdefgh", "stuvwxyz") ); var request = new Request(RequestLine.Get(new Uri("http://xxx/?a=b"))); var authorized = simpleKeyAuthorizer.Authorize(request); var expected = new Uri("http://xxx/?a=b&app_key=abcdefgh&user_access_key=stuvwxyz"); Assert.AreEqual(expected, authorized.RequestLine.Uri); }
public void if_you_supply_invalid_credentials_you_get_an_error() { var authPolicy = new SimpleKeyAuthorizationPolicy( new SimpleKeyAuthorizationCredential("xxx_clearly_invalid", "") ); var theInternetWithSimpleKeyAuthorization = new SystemInternet(authPolicy, new ConsoleLog()); var nodes = new Nodes(theInternetWithSimpleKeyAuthorization, Settings.BaseUrl); var theError = Assert.Throws<Exception>(() => nodes.FindAll()); Assert.That(theError.Message, Is.StringEnding("The server returned status Unauthorized (401), and error message: \"Unauthorized\"")); }
public void it_fails_if_user_access_key_already_present() { var simpleKeyAuthorizer = new SimpleKeyAuthorizationPolicy( new SimpleKeyAuthorizationCredential("abcdefgh", "stuvwxyz") ); var request = new Request(RequestLine.Get(new Uri("http://xxx?user_access_key=1337"))); var theError = Assert.Throws<Exception>(() => simpleKeyAuthorizer.Authorize(request), "Expected an error, but there was none thrown" ); Assert.AreEqual("Request has already been authorized.", theError.Message, "An error was thrown, but the error message does not match." ); }
public void it_does_not_modify_headers_or_payload() { var simpleKeyAuthorizer = new SimpleKeyAuthorizationPolicy( new SimpleKeyAuthorizationCredential("abcdefgh", "stuvwxyz") ); var headers = new NameValueCollection { { "Content-type", "Chubby bat" } }; var payload = new Payload { { "Cletus Spuckler's moustache", "sparse" } }; var request = new Request(RequestLine.Get(new Uri("http://xxx")), headers, payload); var authorized = simpleKeyAuthorizer.Authorize(request); Assert.AreSame(request.Headers, authorized.Headers, "Expected the headers to be unmodified"); Assert.AreSame(request.Payload, authorized.Payload, "Expected the payload to be unmodified"); }