def test_valid_token_header():
    payload = {
        'username': '******',
        'email': '*****@*****.**'
    }
    header = token_validation.generate_token_header(payload, PRIVATE_KEY)
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert 'whiteboardwarrior' == result['username']
def test_valid_token_header_invalid_key():
    payload = {
        'username': '******',
        'email': '*****@*****.**'
    }
    header = token_validation.generate_token_header(payload, PRIVATE_KEY)
    result = token_validation.validate_token_header(header, INVALID_PUBLIC_KEY)
    assert None is result
def test_invalid_token_header_no_expiry_time():
    payload = {
        'username': '******',
    }
    token = token_validation.encode_token(payload, PRIVATE_KEY)
    token = token.decode('utf8')
    header = f'Bearer {token}'
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert None is result
def test_invalid_token_header_no_username():
    expiry = delorean.parse('2020-02-24 13:47:34').datetime
    payload = {
        'exp': expiry,
    }
    token = token_validation.encode_token(payload, PRIVATE_KEY)
    token = token.decode('utf8')
    header = f'Bearer {token}'
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert None is result
def test_invalid_token_no_header():
    header = None
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert None is result
def test_invalid_token_header_bad_token():
    header = 'Bearer baddata'
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert None is result
def test_invalid_token_header_invalid_format():
    header = 'bad header'
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert None is result
예제 #8
0
def authentication_header_parser(token):
    payload = validate_token_header(token, config.PUBLIC_KEY)
    if payload is None:
        abort(401)
    return payload