It turns out it’s because I overlooked an important part of the Persona system, which is
that authentications are only valid for particular domains. We’ve left the domain hard‐
coded as “localhost” in
accounts/authentication.py
:
accounts/authentication.py.
PERSONA_VERIFY_URL
=
'https://verifier.login.persona.org/verify'DOMAIN
=
'localhost'
User
=
get_user_model
()
We can try and hack in a fix on the server:
accounts/authentication.py.
DOMAIN
=
'superlists-staging.ottg.eu'
And check whether it works by doing a manual login. It does.
Fixing the Persona Bug
Here’s how we go about baking in a fix, switching back to coding on our local PC. We
start by moving the definition for the
DOMAIN
variable into
settings.py
, where we can
later use the deploy script to override it:
superlists/settings.py (ch17l011).
# This setting is changed by the deploy script
DOMAIN
=
"localhost"
ALLOWED_HOSTS
=
[
DOMAIN
]
We feed that change back through the tests:
accounts/tests/test_authentication.py.
@@ -1,12 +1,14 @@
from unittest.mock import patch
+from django.conf import settings
from django.contrib.auth import get_user_model
from django.test import TestCase
User = get_user_model()
from accounts.authentication import (
- PERSONA_VERIFY_URL, DOMAIN, PersonaAuthenticationBackend
+ PERSONA_VERIFY_URL, PersonaAuthenticationBackend
)
+
@patch('accounts.authentication.requests.post')
class AuthenticateTest(TestCase):
@@ -21,7 +23,7 @@ class AuthenticateTest(TestCase):
self.backend.authenticate('an assertion')
mock_post.assert_called_once_with(
PERSONA_VERIFY_URL,
- data={'assertion': 'an assertion', 'audience': DOMAIN}
+ data={'assertion': 'an assertion', 'audience': settings.DOMAIN}
)
The Proof Is in the Pudding: Using Staging to Catch Final Bugs
|
309