~nataliabidart/canonical-identity-provider/admin-access-via-sso

« back to all changes in this revision

Viewing changes to src/webui/tests/test_views_account.py

[r=ricardokirkner,james-w] Store only AuthToken hashes in the database.

Since AuthTokens are security-sensitive, once a raw token is generated and sent to the user via either e-mail or URL redirection, the raw value is discarded and only a hash is kept in the database. So raw tokens can't be recovered directly from the database.

The data is stored in the same existing "token" column (though renamed at model-level to "hashed_token").

The code accounts for "old-style", raw tokens to be stored in the same table; all existing tokens continue to be valid and can be used. However, only "new-style", hashed tokens will be stored in the future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
863
863
        self.emailaddress = self.account.emailaddress_set.get()
864
864
        assert self.emailaddress.status == EmailStatus.NEW
865
865
        self.authtoken = AuthToken.objects.create(
866
 
            email=self.email, token=self.token,
 
866
            email=self.email, raw_token=self.token,
867
867
            token_type=AuthTokenType.INVALIDATEEMAIL)
868
868
 
869
869
    def assert_no_changes(self):
913
913
                continue  # will test in the happy path
914
914
 
915
915
            AuthToken.objects.all().delete()
916
 
            token = AuthToken(
917
 
                email=self.email, token=self.token, token_type=t)
 
916
            # Create the token first with a valid type...
 
917
            token = AuthToken.objects.create(
 
918
                email=self.email, raw_token=self.token,
 
919
                token_type=AuthTokenType.INVALIDATEEMAIL)
 
920
            # Now set its type to the desired one
 
921
            token.token_type = t
918
922
            token.save()
919
923
            self.addCleanup(token.delete)
920
924