def test_auth_missing_user_id(): with pytest.raises(HTTPException) as e: token = encode_jwt_payload(test_data.jwt_payload_missing_user_id, JWT_PRIVATE_KEY) authorize_user(f'Bearer {token}') assert e.value.status_code == 401 assert "Unauthorized" in e.value.detail
def test_auth_missing_config_public_key(monkeypatch): monkeypatch.delenv('JWT_PUBLIC_KEY') with pytest.raises(HTTPException) as e: token = encode_jwt_payload(test_data.valid_jwt_payload, JWT_PRIVATE_KEY) authorize_user(f'Bearer {token}') assert e.value.status_code == 500 assert "Internal Server Error" in e.value.detail
def stream_result_fixed(input_query: InputFixedQuery, request: Request, # needed for json_logging.get_correlation_id to work correctly authorization: str = Header(None), processor: Processor = Depends(get_processor)): """ Create result set of data with temporality type fixed, and stream result as response. """ log.info(f'Entering /data/fixed/stream with input query: {input_query}') user_id = authorize_user(authorization) log.info(f"Authorized token for user: {user_id}") result_data = processor.process_fixed_request(input_query) buffer_stream = pa.BufferOutputStream() pq.write_table(result_data, buffer_stream) return PlainTextResponse( buffer_stream.getvalue().to_pybytes() )
def create_file_result_fixed(input_query: InputFixedQuery, request: Request, # needed for json_logging.get_correlation_id to work correctly authorization: str = Header(None), processor: Processor = Depends(get_processor)): """ Create result set of data with temporality type fixed, and write result to file. Returns name of file in response. """ log.info( f'Entering /data/fixed/generate-file with input query: {input_query}' ) user_id = authorize_user(authorization) log.info(f"Authorized token for user: {user_id}") result_data = processor.process_fixed_request(input_query) resultset_file_name = processor.write_table(result_data) log.info(f'File name for event result set: {resultset_file_name}') return { 'filename': resultset_file_name, }
def test_auth_toggled_off(monkeypatch): monkeypatch.setenv('JWT_AUTH', 'false') user_id = authorize_user(None) assert user_id == "default"
def test_auth_missing_token(): with pytest.raises(HTTPException) as e: authorize_user(None) assert e.value.status_code == 401 assert "Unauthorized" in e.value.detail
def test_auth_valid_token(): token = encode_jwt_payload(test_data.valid_jwt_payload, JWT_PRIVATE_KEY) user_id = authorize_user(f'Bearer {token}') assert user_id == test_data.valid_jwt_payload['sub']