Skip to content

Commit

Permalink
fix(api): cover c373930 in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterthomassen committed Aug 11, 2022
1 parent 5c7774f commit aef7eae
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions api/desecapi/tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

from api import settings
from desecapi.models import Domain, User, Captcha
from desecapi.serializers import AuthenticatedActionSerializer
from desecapi.tests.base import DesecTestCase, DomainOwnerTestCase, PublicSuffixMockMixin


Expand Down Expand Up @@ -451,11 +450,23 @@ def _test_registration_with_domain(self, email=None, password=None, domain=None,
confirmation_link = self.assertRegistrationEmail(email)

if tampered_domain is not None:
self.assertNotEqual(domain, tampered_domain)

path = urlparse(confirmation_link).path
serializer_class = resolve(path).func.cls.serializer_class
code = resolve(path).kwargs.get('code')
_, data = AuthenticatedActionSerializer._unpack_code(code, ttl=None)

serializer = serializer_class(data={}, context={'code': code})
serializer.is_valid()
self.assertEqual(serializer.validated_data['domain'], domain) # preparation check: domain as expected

serializer = serializer_class(data={'domain': tampered_domain}, context={'code': code})
serializer.is_valid()
self.assertEqual(serializer.validated_data['domain'], domain) # extra domain from data not injected

_, data = serializer_class._unpack_code(code, ttl=None)
data['domain'] = tampered_domain
tampered_code = AuthenticatedActionSerializer._pack_code(data)
tampered_code = serializer_class._pack_code(data)
confirmation_link = confirmation_link.replace(code, tampered_code)
response = self.client.verify(confirmation_link)
self.assertVerificationFailureInvalidCodeResponse(response)
Expand Down

0 comments on commit aef7eae

Please sign in to comment.