Exemplo n.º 1
0
 def test_invalid_secret(self):
     """
     If the secret used for decoding doesn't match the secret used for
     encoding, return None.
     """
     payload = create_payload()
     signed_request = self.create_signed_request(payload, 'secret')
     eq_(decode_signed_request(signed_request, 'other_secret'), None)
Exemplo n.º 2
0
 def test_invalid_secret(self):
     """
     If the secret used for decoding doesn't match the secret used for
     encoding, return None.
     """
     payload = create_payload()
     signed_request = self.create_signed_request(payload, 'secret')
     eq_(decode_signed_request(signed_request, 'other_secret'), None)
Exemplo n.º 3
0
 def test_safari_workaround(self, fb_redirect, update_user_info):
     """
     If the user is using Safari and hasn't gone through the workaround yet,
     send them to the workaround page.
     """
     fb_redirect.return_value = HttpResponse()
     payload = create_payload(user_id=1)
     with patch('affiliates.facebook.views.absolutify') as mock_absolutify:
         mock_absolutify.return_value = 'test'
         self.load_app(payload, HTTP_USER_AGENT='Safari/5.04')
         mock_absolutify.assert_called_with(reverse('facebook.safari_workaround'))
     fb_redirect.assert_called_with(ANY, 'test', top_window=True)
Exemplo n.º 4
0
    def test_country_missing(self, login, update_user_info):
        """
        If the user's country is not included in the signed_request, keep their
        old country value intact.
        """
        user = FacebookUserFactory.create(country='us')
        payload = create_payload(user_id=user.id)
        del payload['user']['country']
        self.load_app(payload)

        eq_(login.called, True)
        eq_(login.call_args[0][1].country, 'us')
Exemplo n.º 5
0
    def test_country_saved(self, login, update_user_info):
        """
        When a user enters the app, their country should be set and
        login should be called with the updated user object so that it will be
        saved to the database.
        """
        user = FacebookUserFactory.create(country='us')
        payload = create_payload(user_id=user.id, country='fr')
        self.load_app(payload)

        eq_(login.called, True)
        eq_(login.call_args[0][1].country, 'fr')
Exemplo n.º 6
0
    def test_country_saved(self, login, update_user_info):
        """
        When a user enters the app, their country should be set and
        login should be called with the updated user object so that it will be
        saved to the database.
        """
        user = FacebookUserFactory.create(country='us')
        payload = create_payload(user_id=user.id, country='fr')
        self.load_app(payload)

        eq_(login.called, True)
        eq_(login.call_args[0][1].country, 'fr')
Exemplo n.º 7
0
    def test_country_missing(self, login, update_user_info):
        """
        If the user's country is not included in the signed_request, keep their
        old country value intact.
        """
        user = FacebookUserFactory.create(country='us')
        payload = create_payload(user_id=user.id)
        del payload['user']['country']
        self.load_app(payload)

        eq_(login.called, True)
        eq_(login.call_args[0][1].country, 'us')
Exemplo n.º 8
0
    def test_no_authorization(self, fb_redirect, update_user_info):
        """
        If the user has yet to authorize the app, redirect them to the pre-auth
        promo page.
        """
        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=None)
        response = self.load_app(payload)

        eq_(response, fb_redirect.return_value)
        with self.activate('en-US'):
            ok_(fb_redirect.call_args[0][1]
                .endswith(reverse('facebook.pre_auth_promo')))
Exemplo n.º 9
0
 def test_safari_workaround(self, fb_redirect, update_user_info):
     """
     If the user is using Safari and hasn't gone through the workaround yet,
     send them to the workaround page.
     """
     fb_redirect.return_value = HttpResponse()
     payload = create_payload(user_id=1)
     with patch('affiliates.facebook.views.absolutify') as mock_absolutify:
         mock_absolutify.return_value = 'test'
         self.load_app(payload, HTTP_USER_AGENT='Safari/5.04')
         mock_absolutify.assert_called_with(
             reverse('facebook.safari_workaround'))
     fb_redirect.assert_called_with(ANY, 'test', top_window=True)
Exemplo n.º 10
0
    def test_no_authorization(self, fb_redirect, update_user_info):
        """
        If the user has yet to authorize the app, redirect them to the pre-auth
        promo page.
        """
        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=None)
        response = self.load_app(payload)

        eq_(response, fb_redirect.return_value)
        with self.activate('en-US'):
            ok_(fb_redirect.call_args[0][1].endswith(
                reverse('facebook.pre_auth_promo')))
Exemplo n.º 11
0
    def test_no_safari_workaround(self, fb_redirect, update_user_info):
        """
        If the user is not using Safari, do not redirect to the workaround.
        """
        with self.activate('en-US'):
            workaround_url = absolutify(reverse('facebook.safari_workaround'))

        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=1)
        response = self.load_app(payload,
                                 HTTP_USER_AGENT='Safari/5.04 Chrome/7.5')

        eq_(response, fb_redirect.return_value)
        ok_(fb_redirect.call_args[0][1] != workaround_url)
Exemplo n.º 12
0
    def test_no_safari_workaround(self, fb_redirect, update_user_info):
        """
        If the user is not using Safari, do not redirect to the workaround.
        """
        with self.activate('en-US'):
            workaround_url = absolutify(reverse('facebook.safari_workaround'))

        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=1)
        response = self.load_app(payload,
                                 HTTP_USER_AGENT='Safari/5.04 Chrome/7.5')

        eq_(response, fb_redirect.return_value)
        ok_(fb_redirect.call_args[0][1] != workaround_url)
Exemplo n.º 13
0
    def test_has_authorization(self, fb_redirect, update_user_info):
        """
        If the user has authorized the app and isn't new, redirect to the main
        banner view.
        """
        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=1)
        response = self.load_app(payload)

        # Assert that the return value of fb_redirect was returned, and that
        # fb_redirect was given a url that ends with the banner_list url.
        eq_(response, fb_redirect.return_value)
        with self.activate('en-US'):
            ok_(fb_redirect.call_args[0][1]
                .endswith(reverse('facebook.banner_list')))
Exemplo n.º 14
0
    def test_has_authorization(self, fb_redirect, update_user_info):
        """
        If the user has authorized the app and isn't new, redirect to the main
        banner view.
        """
        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=1)
        response = self.load_app(payload)

        # Assert that the return value of fb_redirect was returned, and that
        # fb_redirect was given a url that ends with the banner_list url.
        eq_(response, fb_redirect.return_value)
        with self.activate('en-US'):
            ok_(fb_redirect.call_args[0][1].endswith(
                reverse('facebook.banner_list')))
Exemplo n.º 15
0
    def test_safari_workaround_done(self, fb_redirect, update_user_info):
        """
        If the user is using Safari and hasthe workaround cookie, do not send
        them to the workaround page.
        """
        with self.activate('en-US'):
            workaround_url = absolutify(reverse('facebook.safari_workaround'))

        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=1)
        self.client.cookies[SAFARI_WORKAROUND_KEY] = '1'
        response = self.load_app(payload, HTTP_USER_AGENT='Safari/5.04')
        del self.client.cookies[SAFARI_WORKAROUND_KEY]

        # Ensure that the redirect URL is NOT the safari workaround url
        eq_(response, fb_redirect.return_value)
        ok_(fb_redirect.call_args[0][1] != workaround_url)
Exemplo n.º 16
0
    def test_safari_workaround_done(self, fb_redirect, update_user_info):
        """
        If the user is using Safari and hasthe workaround cookie, do not send
        them to the workaround page.
        """
        with self.activate('en-US'):
            workaround_url = absolutify(reverse('facebook.safari_workaround'))

        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=1)
        self.client.cookies[SAFARI_WORKAROUND_KEY] = '1'
        response = self.load_app(payload, HTTP_USER_AGENT='Safari/5.04')
        del self.client.cookies[SAFARI_WORKAROUND_KEY]

        # Ensure that the redirect URL is NOT the safari workaround url
        eq_(response, fb_redirect.return_value)
        ok_(fb_redirect.call_args[0][1] != workaround_url)
Exemplo n.º 17
0
 def test_valid_request(self):
     """If the signed request is valid, return the decoded payload."""
     payload = create_payload()
     signed_request = self.create_signed_request(payload, 'secret')
     eq_(decode_signed_request(signed_request, 'secret'), payload)
Exemplo n.º 18
0
 def test_invalid_algorithm(self):
     """If the declared algorithm isn't supported, return None."""
     payload = create_payload(algorithm='not-supported')
     signed_request = self.create_signed_request(payload, 'secret')
     eq_(decode_signed_request(signed_request, 'secret'), None)
Exemplo n.º 19
0
 def test_valid_request(self):
     """If the signed request is valid, return the decoded payload."""
     payload = create_payload()
     signed_request = self.create_signed_request(payload, 'secret')
     eq_(decode_signed_request(signed_request, 'secret'), payload)
Exemplo n.º 20
0
 def test_invalid_algorithm(self):
     """If the declared algorithm isn't supported, return None."""
     payload = create_payload(algorithm='not-supported')
     signed_request = self.create_signed_request(payload, 'secret')
     eq_(decode_signed_request(signed_request, 'secret'), None)