Пример #1
0
    def test_decode_invitation_token_returns_an_error_and_role_if_token_expired(
            self, decode_time, expected_result, email_app):
        with freeze_time('2015-01-02 03:04:05'):
            data = {
                'email_address': '*****@*****.**',
                'supplier_id': 1234,
                'supplier_name': 'A. Supplier',
                'role': 'supplier'
            }
            token = generate_token(
                data,
                email_app.config['SHARED_EMAIL_KEY'],
                email_app.config.get('INVITE_EMAIL_TOKEN_NS')
                or email_app.config.get('INVITE_EMAIL_SALT'),
            )

        with freeze_time(decode_time):
            with email_app.app_context():
                if expected_result == 'ok':
                    assert decode_invitation_token(token) == data
                else:
                    assert decode_invitation_token(token) == {
                        'error': 'token_expired',
                        'role': 'supplier'
                    }
Пример #2
0
def test_decode_invitation_token_adds_the_role_key_to_old_style_buyer_tokens(
        email_app):
    data = {'email_address': '*****@*****.**'}
    token = generate_token(data, 'Key', 'Salt')

    with email_app.app_context():
        assert decode_invitation_token(token) == {
            'email_address': '*****@*****.**',
            'role': 'buyer'
        }
Пример #3
0
    def test_decode_invitation_token_adds_the_role_key_to_expired_old_style_buyer_tokens(
            self, email_app):
        with freeze_time('2015-01-02 03:04:05'):
            data = {'email_address': '*****@*****.**'}
            token = generate_token(data, 'Key', 'Salt')

        with email_app.app_context():
            assert decode_invitation_token(token) == {
                'error': 'token_expired',
                'role': 'buyer'
            }
Пример #4
0
 def test_decode_invitation_token_decodes_ok(self, email_app):
     with email_app.app_context():
         # works with arbitrary fields
         data = {
             'email_address': '*****@*****.**',
             'supplier_id': 1234,
             'foo': 'bar',
             'role': 'supplier'
         }
         token = generate_token(data, 'Key', 'Salt')
         assert decode_invitation_token(token) == data
Пример #5
0
def test_decode_invitation_token_returns_an_error_if_token_invalid(email_app):
    with email_app.app_context():
        data = {
            'email_address': '*****@*****.**',
            'supplier_id': 1234,
            'supplier_name': 'A. Supplier',
            'role': 'supplier'
        }
        token = generate_token(data, email_app.config['SHARED_EMAIL_KEY'],
                               email_app.config['INVITE_EMAIL_SALT'])[1:]

        assert decode_invitation_token(token) == {'error': 'token_invalid'}
Пример #6
0
def test_decode_invitation_token_returns_an_error_and_role_if_token_expired(
        email_app):
    with freeze_time('2015-01-02 03:04:05'):
        data = {
            'email_address': '*****@*****.**',
            'supplier_id': 1234,
            'supplier_name': 'A. Supplier',
            'role': 'supplier'
        }
        token = generate_token(data, email_app.config['SHARED_EMAIL_KEY'],
                               email_app.config['INVITE_EMAIL_SALT'])
    with email_app.app_context():

        assert decode_invitation_token(token) == {
            'error': 'token_expired',
            'role': 'supplier'
        }