diff --git a/legal-api/pyproject.toml b/legal-api/pyproject.toml index 2222275628..cb119ee4ea 100644 --- a/legal-api/pyproject.toml +++ b/legal-api/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "legal-api" -version = "3.1.14" +version = "3.1.15" description = "" authors = [ {name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"} diff --git a/legal-api/src/legal_api/resources/v2/business/business_filings/business_documents.py b/legal-api/src/legal_api/resources/v2/business/business_filings/business_documents.py index 61fb8bd556..7cd095e3a3 100644 --- a/legal-api/src/legal_api/resources/v2/business/business_filings/business_documents.py +++ b/legal-api/src/legal_api/resources/v2/business/business_filings/business_documents.py @@ -26,6 +26,7 @@ from flask_pydantic import validate as pydantic_validate from pydantic import BaseModel +from business_account import AccountService from business_common.utils.legislation_datetime import LegislationDatetime from business_model.models import Business, Document, UserRoles from business_model.models import Filing as FilingModel @@ -118,7 +119,7 @@ def get_documents(identifier: str, # noqa: PLR0911, PLR0912 if legal_filing_name: if legal_filing_name.lower().startswith("receipt"): - return _get_receipt(business, filing, jwt.get_token_auth_header()) + return _get_receipt(business, filing) return get_pdf(filing.storage, legal_filing_name) elif file_key and (document := Document.find_by_file_key(file_key)): @@ -206,7 +207,7 @@ def _get_document_list(business: Business, filing: Filing): return jsonify(document_list), HTTPStatus.OK -def _get_receipt(business: Business, filing: Filing, token): +def _get_receipt(business: Business, filing: Filing): """Get the receipt for the filing.""" if filing.status not in ( Filing.Status.COMPLETED, @@ -223,8 +224,8 @@ def _get_receipt(business: Business, filing: Filing, token): filing.filing_type == "noticeOfWithdrawal" ): effective_date = LegislationDatetime.format_as_report_string(filing.storage.effective_date) - - headers = {"Authorization": "Bearer " + token} + service_token = AccountService.get_bearer_token() + headers = {"Authorization": "Bearer " + service_token} add_account_linking_key_header(headers) corp_name = _get_corp_name(business, filing.storage) diff --git a/legal-api/tests/unit/resources/v2/test_business_filings/test_filing_documents.py b/legal-api/tests/unit/resources/v2/test_business_filings/test_filing_documents.py index 26b2f56cdf..6b893e0898 100644 --- a/legal-api/tests/unit/resources/v2/test_business_filings/test_filing_documents.py +++ b/legal-api/tests/unit/resources/v2/test_business_filings/test_filing_documents.py @@ -1962,7 +1962,7 @@ def test_temp_document_list_for_various_filing_states(app, mocker, session, clie assert rv_data == expected -def test_get_receipt(session, client, jwt, requests_mock): +def test_get_receipt(session, client, jwt, requests_mock, mocker): """Assert that a receipt is generated.""" from legal_api.resources.v2.business.business_filings.business_documents import _get_receipt @@ -1990,15 +1990,17 @@ def test_get_receipt(session, client, jwt, requests_mock): json={'foo': 'bar'}, status_code=HTTPStatus.CREATED) - token = helper_create_jwt(jwt, roles=[STAFF_ROLE], username='username') + service_token = 'service-token-abc' + mocker.patch('business_account.AccountService.get_bearer_token', return_value=service_token) - content, status_code = _get_receipt(business, filing_core, token) + content, status_code = _get_receipt(business, filing_core) assert status_code == HTTPStatus.CREATED assert requests_mock.called_once + assert requests_mock.last_request.headers.get('Authorization') == f'Bearer {service_token}' -def test_get_receipt_request_mock(session, client, jwt, requests_mock): +def test_get_receipt_request_mock(session, client, jwt, requests_mock, mocker): """Assert that a receipt is generated.""" from legal_api.resources.v2.business.business_filings.business_documents import _get_receipt @@ -2025,6 +2027,9 @@ def test_get_receipt_request_mock(session, client, jwt, requests_mock): json={'foo': 'bar'}, status_code=HTTPStatus.CREATED) + service_token = 'service-token-abc' + mocker.patch('business_account.AccountService.get_bearer_token', return_value=service_token) + rv = client.get(f'/api/v2/businesses/{identifier}/filings/{filing.id}/documents/receipt', headers=create_header(jwt, [STAFF_ROLE], @@ -2033,10 +2038,11 @@ def test_get_receipt_request_mock(session, client, jwt, requests_mock): ) assert rv.status_code == HTTPStatus.CREATED - assert requests_mock.called_once + assert requests_mock.called + assert requests_mock.last_request.headers.get('Authorization') == f'Bearer {service_token}' -def test_get_receipt_forwards_account_linking_key(session, client, jwt, requests_mock): +def test_get_receipt_forwards_account_linking_key(session, client, jwt, requests_mock, mocker): """Assert that the receipt call forwards the Account-Linking-Key header when present on the request.""" identifier = 'CP7654321' business = factory_business(identifier) @@ -2060,6 +2066,8 @@ def test_get_receipt_forwards_account_linking_key(session, client, jwt, requests json={'foo': 'bar'}, status_code=HTTPStatus.CREATED) + mocker.patch('business_account.AccountService.get_bearer_token', return_value='service-token') + rv = client.get(f'/api/v2/businesses/{identifier}/filings/{filing.id}/documents/receipt', headers=create_header(jwt, [STAFF_ROLE],