Beispiel #1
0
class BrowserIDSessionBackendTests(TestCase):
    fixtures = ['registered_users']

    def setUp(self):
        self.backend = BrowserIDSessionBackend()
        self.factory = SessionRequestFactory()

    def _auth(self, email, assertion='asdf'):
        request = self.factory.get(reverse('home'))
        with mock_browserid(email):
            return self.backend.authenticate(request, assertion)

    def test_invalid_assertion(self):
        """Return None if the assertion is invalid."""
        result = self._auth(None)
        eq_(result, None)

    def test_invalid_user(self):
        """Return None if the user does not exist."""
        result = self._auth('*****@*****.**')
        eq_(result, None)

    def test_valid_user(self):
        """Return the User object if a user exists."""
        result = self._auth('*****@*****.**')
        ok_(isinstance(result, User))
        eq_(result.email, '*****@*****.**')
Beispiel #2
0
class VerifyTests(TestCase):
    def setUp(self):
        self.factory = SessionRequestFactory()

    def _verify(self, assertion=None, email=None):
        with self.activate('en-US'):
            request = self.factory.get(reverse('home'))
        if email:
            request.session[SESSION_VERIFY] = self._verification(email)

        return verify(request, assertion)

    def _verification(self, email):
        return {'status': 'okay', 'email': email}

    @mock_browserid(None)
    def test_invalid_assertion(self):
        """Return None if the assertion is invalid."""
        result = self._verify('asdf')
        eq_(result, None)

    @mock_browserid('*****@*****.**')
    def test_valid_assertion(self):
        """Return verification if the assertion is valid."""
        result = self._verify('asdf')
        eq_(result['status'], 'okay')
        eq_(result['email'], '*****@*****.**')

    @mock_browserid('*****@*****.**')
    @patch('browserid.utils.browserid_verify')
    def test_cached_verification(self, browserid_verify):
        """
        Return verification without connecting to BrowserID if verification
        is cached in session.
        """
        result = self._verify(email='*****@*****.**')
        eq_(result['status'], 'okay')
        eq_(result['email'], '*****@*****.**')
        ok_(not browserid_verify.called, 'browserid_verify was called.')

        # Test that a non-cached call works, in case we mocked incorrectly
        result = self._verify('asdf')
        ok_(browserid_verify.called, 'browserid_verify was not called.')
Beispiel #3
0
class VerifyTests(TestCase):
    def setUp(self):
        self.factory = SessionRequestFactory()

    def _verify(self, assertion=None, email=None):
        with self.activate("en-US"):
            request = self.factory.get(reverse("home"))
        if email:
            request.session[SESSION_VERIFY] = self._verification(email)

        return verify(request, assertion)

    def _verification(self, email):
        return {"status": "okay", "email": email}

    @mock_browserid(None)
    def test_invalid_assertion(self):
        """Return None if the assertion is invalid."""
        result = self._verify("asdf")
        eq_(result, None)

    @mock_browserid("*****@*****.**")
    def test_valid_assertion(self):
        """Return verification if the assertion is valid."""
        result = self._verify("asdf")
        eq_(result, self._verification("*****@*****.**"))

    @mock_browserid("*****@*****.**")
    @patch("browserid.utils.browserid_verify")
    def test_cached_verification(self, browserid_verify):
        """
        Return verification without connecting to BrowserID if verification
        is cached in session.
        """
        result = self._verify(email="*****@*****.**")
        eq_(result, self._verification("*****@*****.**"))
        ok_(not browserid_verify.called, "browserid_verify was called.")

        # Test that a non-cached call works, in case we mocked incorrectly
        result = self._verify("asdf")
        ok_(browserid_verify.called, "browserid_verify was not called.")