Ejemplo n.º 1
0
    def test_login(self):
        """Tests when setting the user info with and without continue URL."""
        host = 'foo.com:1234'
        path_info = '/_ah/login'
        cookie_dict = {}
        action = 'Login'
        set_email = EMAIL
        set_admin = False
        continue_url = ''

        expected_set = login._set_user_info_cookie(set_email,
                                                   set_admin).strip()

        # No continue URL.
        status, location, set_cookie, _ = self._run_test(
            host, path_info, cookie_dict, action, set_email, set_admin,
            continue_url)
        self.assertEqual(302, status)
        self.assertEqual('http://%s%s' % (host, path_info), location)
        self.assertEqual(expected_set, set_cookie)
        self.assertIsInstance(location, str)
        self.assertIsInstance(set_cookie, str)

        # Continue URL.
        continue_url = 'http://foo.com/blah'
        status, location, set_cookie, _ = self._run_test(
            host, path_info, cookie_dict, action, set_email, set_admin,
            continue_url)
        self.assertEqual(302, status)
        self.assertEqual(continue_url, location)
        self.assertEqual(expected_set, set_cookie)
        self.assertIsInstance(location, str)
        self.assertIsInstance(set_cookie, str)
Ejemplo n.º 2
0
  def test_login(self):
    """Tests when setting the user info with and without continue URL."""
    host = 'foo.com:1234'
    path_info = '/_ah/login'
    cookie_dict = {}
    action = 'Login'
    set_email = EMAIL
    set_admin = False
    continue_url = ''

    expected_set = login._set_user_info_cookie(set_email, set_admin).strip()

    # No continue URL.
    status, location, set_cookie, _ = self._run_test(
        host, path_info, cookie_dict, action, set_email, set_admin,
        continue_url)
    self.assertEqual(302, status)
    self.assertEqual('http://%s%s' % (host, path_info), location)
    self.assertEqual(expected_set, set_cookie)
    self.assertIsInstance(location, str)
    self.assertIsInstance(set_cookie, str)

    # Continue URL.
    continue_url = 'http://foo.com/blah'
    status, location, set_cookie, _ = self._run_test(
        host, path_info, cookie_dict, action, set_email, set_admin,
        continue_url)
    self.assertEqual(302, status)
    self.assertEqual(continue_url, location)
    self.assertEqual(expected_set, set_cookie)
    self.assertIsInstance(location, str)
    self.assertIsInstance(set_cookie, str)
Ejemplo n.º 3
0
  def test_set_user_info_cookie(self):
    """Tests the set_user_info_cookie function."""
    cookie_value = '%s:True:%s' % (EMAIL, USER_ID)
    expected_result = '%s="%s"; Path=/' % (COOKIE_NAME, cookie_value)

    result = login._set_user_info_cookie(EMAIL, True, cookie_name=COOKIE_NAME)

    self.assertEqual(expected_result, result)
Ejemplo n.º 4
0
  def test_set_user_info_cookie(self):
    """Tests the set_user_info_cookie function."""
    cookie_value = '%s:True:%s' % (EMAIL, USER_ID)
    expected_result = '%s="%s"; Path=/' % (COOKIE_NAME, cookie_value)

    result = login._set_user_info_cookie(EMAIL, True, cookie_name=COOKIE_NAME)

    self.assertEqual(expected_result, result)
Ejemplo n.º 5
0
        def login_step2(code, continue_url):
            token_params = {
                'code': code,
                'client_id': client_id,
                'client_secret': client_secret,
                'redirect_uri': base_url + login.LOGIN_URL_RELATIVE,
                'grant_type': 'authorization_code',
            }
            data = request('POST', OAUTH2_TOKENURL, token_params)
            token = data.get('access_token')
            if not token:
                error('No token in response: ' + str(data))
                return

            email, is_admin = get_user_info(token)
            if not email:
                error('No email address in response: ' + str(data))
                return
            self.response.headers['Set-Cookie'] = login._set_user_info_cookie(email, is_admin)
            redirect(continue_url)