示例#1
0
    def generate_session_token(self, save=True):
        """ Generate new session token and key pair. Used to validate sessions. """
        key, token = generate_token()
        self.profile[SESSION_TOKEN] = token
        self.profile[SESSION_KEY] = key
        if save:
            self.save()

        return token
示例#2
0
    def test_validtoken(self):
        """ validate the token """
        test_key, test_token = crypto.generate_token(
            key='MoinMoin')  # having some key value
        result = crypto.valid_token(test_key, test_token)
        assert result

        test_key, test_token = crypto.generate_token()  # key value is none
        result = crypto.valid_token(test_key, test_token)
        assert result

        test_parts = test_token.split('-')
        test_parts[0] = 'not_valid'
        # changed value of the first part, should not be string
        test_token_changed = '-'.join(test_parts)
        result = crypto.valid_token(test_key, test_token_changed)
        assert not result

        test_key, test_token = 'MoinMoin', 'incorrect_token'
        result = crypto.valid_token(test_key, test_token)
        assert not result
示例#3
0
 def generate_recovery_token(self):
     key, token = generate_token()
     self.profile[RECOVERPASS_KEY] = key
     self.save()
     return token