Beispiel #1
0
    def test_login_succeful(self):
        response = self.client.get(self.reverse('begin', 'twitter'))
        # authenticator must redirect to service page
        self.assertEqual(response.status_code, 302)

        # Open first redirect page, it contains user login form because
        # we don't have cookie to send to twitter
        login_content = self.get_content(response['Location'])
        parser = FormParserByID('login_form')
        parser.feed(login_content)
        auth = {'session[username_or_email]': self.user,
                'session[password]': self.passwd}

        # Check that action and values were loaded properly
        self.assertTrue(parser.action)
        self.assertTrue(parser.values)

        # Post login form, will return authorization or redirect page
        parser.values.update(auth)
        content = self.get_content(parser.action, data=parser.values)

        # If page contains a form#login_form, then we are in the app
        # authorization page because the app is not authorized yet,
        # otherwise the app already gained permission and twitter sends
        # a page that redirects to redirect_url
        if 'login_form' in content:
            # authorization form post, returns redirect_page
            parser = FormParserByID('login_form').feed(content)
            self.assertTrue(parser.action)
            self.assertTrue(parser.values)
            parser.values.update(auth)
            redirect_page = self.get_content(parser.action, data=parser.values)
        else:
            redirect_page = content

        parser = RefreshParser()
        parser.feed(redirect_page)
        self.assertTrue(parser.value)

        response = self.client.get(self.make_relative(parser.value))
        self.assertEqual(response.status_code, 302)
        location = self.make_relative(response['Location'])
        login_redirect = getattr(settings, 'LOGIN_REDIRECT_URL', '')
        self.assertTrue(location == login_redirect)
    def test_login_succeful(self):
        response = self.client.get(self.reverse('begin', 'facebook'))
        # authenticator must redirect to service page
        self.assertEqual(response.status_code, 302)

        # Open first redirect page, it contains user login form because
        # we don't have cookie to send to twitter
        parser = FormParserByID('login_form')
        parser.feed(self.get_content(response['Location'], use_cookies=True))
        auth = {'email': self.user,
                'pass': self.passwd}

        # Check that action and values were loaded properly
        self.assertTrue(parser.action)
        self.assertTrue(parser.values)

        # Post login form, will return authorization or redirect page
        parser.values.update(auth)
        content = self.get_content(parser.action, parser.values,
                                   use_cookies=True)

        # If page contains a form#login_form, then we are in the app
        # authorization page because the app is not authorized yet,
        # otherwise the app already gained permission and twitter sends
        # a page that redirects to redirect_url
        if 'uiserver_form' in content:
            # authorization form post, returns redirect_page
            parser = FormParserByID('uiserver_form').feed(content)
            self.assertTrue(parser.action)
            self.assertTrue(parser.values)
            parser.values.update(auth)
            redirect_page = self.get_content(parser.action, parser.values,
                                             use_cookies=True)
        else:
            redirect_page = content

        url = REDIRECT_RE.findall(redirect_page)
        self.assertTrue(url)
        # URL comes on JS scaped, needs to be clean first, any better way?
        url = url[0].replace('\u0025', '%').replace('\\', '')
        response = self.client.get(self.make_relative(url))
Beispiel #3
0
    def test_login_succeful(self):
        response = self.client.get(self.reverse('begin', 'google'))

        parser = FormParserByID('openid_message')
        parser.feed(response.content)
        # Check that action and values were loaded properly
        self.assertTrue(parser.action)
        self.assertTrue(parser.values)
        content = self.get_content(parser.action, parser.values, use_cookies=True)

        parser = FormParserByID('gaia_loginform')
        parser.feed(content)
        auth = {'Email': self.user, 'Passwd': self.passwd}
        parser.values.update(auth)
        # Check that action and values were loaded properly
        self.assertTrue(parser.action)
        self.assertTrue(parser.values)

        content = self.get_content(parser.action, parser.values, use_cookies=True)
        parser = RefreshParser()
        parser.feed(content)

        # approved?
        result = self.get_redirect(parser.value, use_cookies=True)
        if result.headers.get('Location', ''):  # approved?
            # damn, google has a hell of redirects :-(
            result = self.get_redirect(result.headers['Location'], use_cookies=True)
            result = self.get_redirect(result.headers['Location'], use_cookies=True)
            result = self.get_redirect(result.headers['Location'], use_cookies=True)

        # app was not approved
        if self.SERVER_NAME not in result.headers.get('Location', ''):
            content = self.get_content(parser.value, use_cookies=True)
            parser = FormParser()
            parser.feed(content)
            parser.values['submit_true'] = 'yes'
            parser.values['remember_choices'] = 'yes'
            result = self.get_redirect(parser.action, parser.values, use_cookies=True)

        response = self.client.get(self.make_relative(result.headers['Location']))
        self.assertTrue(settings.LOGIN_REDIRECT_URL in self.make_relative(response['Location']))