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
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
def authentication_header_parser(value): username = validate_token_header(value, config.PUBLIC_KEY) if username is None: abort(401) return username
def test_valid_token_header(): header = token_validation.generate_token_header('tonystark', PRIVATE_KEY) result = token_validation.validate_token_header(header, PUBLIC_KEY) assert 'tonystark' == result
def test_valid_token_header_invalid_key(): header = token_validation.generate_token_header('tonystark', PRIVATE_KEY) result = token_validation.validate_token_header(header, INVALID_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