Example #1
0
 def test_openid_callback_redirect_fallback(self):
     # If OpenID callback request was a POST or GET with no form or query
     # string values at all, then the application URL is used.
     view = OpenIDCallbackView(context=None, request=None)
     view.request = LaunchpadTestRequest(SERVER_URL=self.APPLICATION_URL)
     view._redirect()
     self.assertEquals(
         httplib.TEMPORARY_REDIRECT, view.request.response.getStatus())
     self.assertEquals(
         view.request.response.getHeader('Location'), self.APPLICATION_URL)
Example #2
0
 def test_get_requested_url(self):
     # The OpenIDCallbackView needs to pass the currently-being-requested
     # URL to the OpenID library.  OpenIDCallbackView._get_requested_url
     # returns the URL.
     request = LaunchpadTestRequest(
         SERVER_URL='http://example.com',
         QUERY_STRING='foo=bar',
         form={'starting_url': 'http://launchpad.dev/after-login'})
     view = OpenIDCallbackView(context=None, request=None)
     url = view._get_requested_url(request)
     self.assertEquals(url, 'http://example.com?foo=bar')
Example #3
0
 def test_open_id_callback_redirect_from_post(self):
     # If OpenID callback request was a POST, the starting_url is extracted
     # correctly.
     view = OpenIDCallbackView(context=None, request=None)
     view.request = LaunchpadTestRequest(
         SERVER_URL=self.APPLICATION_URL, form={'fake': 'value'},
         QUERY_STRING='starting_url=' + self.STARTING_URL)
     view._redirect()
     self.assertEquals(
         httplib.TEMPORARY_REDIRECT, view.request.response.getStatus())
     self.assertEquals(
         view.request.response.getHeader('Location'), self.STARTING_URL)
Example #4
0
 def test_gather_params_with_unicode_data(self):
     # If the currently requested URL includes a query string, the
     # parameters in the query string will be included when constructing
     # the params mapping (which is then used to complete the open ID
     # response) and if there are non-ASCII characters in the query string,
     # they are properly decoded.
     request = LaunchpadTestRequest(SERVER_URL='http://example.com',
                                    QUERY_STRING='foo=%E1%9B%9D',
                                    environ={'PATH_INFO': '/'})
     view = OpenIDCallbackView(context=None, request=None)
     params = view._gather_params(request)
     self.assertEqual(params['foo'], u'\u16dd')
Example #5
0
 def test_gather_params_with_unicode_data(self):
     # If the currently requested URL includes a query string, the
     # parameters in the query string will be included when constructing
     # the params mapping (which is then used to complete the open ID
     # response) and if there are non-ASCII characters in the query string,
     # they are properly decoded.
     request = LaunchpadTestRequest(
         SERVER_URL='http://example.com',
         QUERY_STRING='foo=%E1%9B%9D',
         environ={'PATH_INFO': '/'})
     view = OpenIDCallbackView(context=None, request=None)
     params = view._gather_params(request)
     self.assertEquals(params['foo'], u'\u16dd')
Example #6
0
 def test_gather_params(self):
     # If the currently requested URL includes a query string, the
     # parameters in the query string must be included when constructing
     # the params mapping (which is then used to complete the open ID
     # response).  OpenIDCallbackView._gather_params does that gathering.
     request = LaunchpadTestRequest(
         SERVER_URL='http://example.com',
         QUERY_STRING='foo=bar',
         form={'starting_url': 'http://launchpad.dev/after-login'},
         environ={'PATH_INFO': '/'})
     view = OpenIDCallbackView(context=None, request=None)
     params = view._gather_params(request)
     expected_params = {
         'starting_url': 'http://launchpad.dev/after-login',
         'foo': 'bar',
     }
     self.assertEquals(params, expected_params)
Example #7
0
 def test_unexpected_multivalue_fields(self):
     # The parameter gatering doesn't expect to find multi-valued form
     # field and it reports an error if it finds any.
     request = LaunchpadTestRequest(SERVER_URL='http://example.com',
                                    QUERY_STRING='foo=1&foo=2',
                                    environ={'PATH_INFO': '/'})
     view = OpenIDCallbackView(context=None, request=None)
     self.assertRaises(ValueError, view._gather_params, request)
Example #8
0
 def test_open_id_callback_redirect_from_get(self):
     # If OpenID callback request was a GET, the starting_url is extracted
     # correctly.
     view = OpenIDCallbackView(context=None, request=None)
     view.request = LaunchpadTestRequest(
         SERVER_URL=self.APPLICATION_URL,
         form={'starting_url': self.STARTING_URL})
     view.initialize()
     view._redirect()
     self.assertEqual(httplib.TEMPORARY_REDIRECT,
                      view.request.response.getStatus())
     self.assertEqual(view.request.response.getHeader('Location'),
                      self.STARTING_URL)
 def setupLoggedInRequest(self, user, request, when=None):
     """Test helper to login a user for a request."""
     with person_logged_in(user):
         view = OpenIDCallbackView(user, request)
         view.login(user, when)
Example #10
0
 def setupLoggedInRequest(self, user, request, when=None):
     """Test helper to login a user for a request."""
     with person_logged_in(user):
         view = OpenIDCallbackView(user, request)
         view.login(user, when)