Esempio n. 1
0
def test_invalid_token_header_not_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
Esempio n. 2
0
def test_invalid_token_header_no_username():
    expiry = delorean.parse('2018-05-17 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
Esempio n. 3
0
def test_valid_token_header():
    header = token_validation.generate_token_header('alice', PRIVATE_KEY)
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert 'alice' == result
Esempio n. 4
0
def test_valid_token_header_invalid_key():
    header = token_validation.generate_token_header('alice', PRIVATE_KEY)
    result = token_validation.validate_token_header(header, INVALID_PUBLIC_KEY)
    assert None is result
Esempio n. 5
0
def test_invalid_token_no_header():
    header = None
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert None is result
Esempio n. 6
0
def test_invalid_token_header_bad_token():
    header = 'Bearer baddata'
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert None is result
Esempio n. 7
0
def test_invalid_token_header_invalid_format():
    header = 'bad header'
    result = token_validation.validate_token_header(header, PUBLIC_KEY)
    assert None is result
def authentication_header_parser(value):
    username = validate_token_header(value, config.PUBLIC_KEY)
    if username is None:
        abort(401)
    return username