mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-10-05 18:51:57 +00:00
Fix auth config check and URL escaping in form
- _google_auth_configured() now checks env var presence (intent), not the fetched SSM value — prevents silent auth bypass if SSM param is deleted - Add </script> escaping to URL values in generate_form.py for consistency with other injected values
This commit is contained in:
parent
1129718685
commit
0fbb0c71f2
3 changed files with 12 additions and 18 deletions
|
|
@ -65,7 +65,7 @@ def _get_discount_settings() -> tuple[Decimal, Decimal]:
|
||||||
|
|
||||||
|
|
||||||
def _google_auth_configured() -> bool:
|
def _google_auth_configured() -> bool:
|
||||||
return bool(_get_google_client_id())
|
return bool(os.environ.get("GOOGLE_CLIENT_ID_PARAM", ""))
|
||||||
|
|
||||||
|
|
||||||
def _is_parameter_not_found(exc: Exception) -> bool:
|
def _is_parameter_not_found(exc: Exception) -> bool:
|
||||||
|
|
@ -204,15 +204,7 @@ def handle_submit(event):
|
||||||
# If SSM fetch fails for any other reason, fail closed (503).
|
# If SSM fetch fails for any other reason, fail closed (503).
|
||||||
google_token = body.get("google_id_token")
|
google_token = body.get("google_id_token")
|
||||||
|
|
||||||
try:
|
if _google_auth_configured():
|
||||||
google_auth_configured = _google_auth_configured()
|
|
||||||
except Exception as exc:
|
|
||||||
logger.error("SSM fetch failed for Google client ID: %s", exc)
|
|
||||||
return response(
|
|
||||||
503, {"error": "Authentication service temporarily unavailable"}
|
|
||||||
)
|
|
||||||
|
|
||||||
if google_auth_configured:
|
|
||||||
try:
|
try:
|
||||||
client_id = _get_google_client_id()
|
client_id = _get_google_client_id()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,15 @@ def generate_form(
|
||||||
deadline = config.get("order_deadline", "Thursday 11:59 PM")
|
deadline = config.get("order_deadline", "Thursday 11:59 PM")
|
||||||
week = datetime.now().strftime("%Y-W%U")
|
week = datetime.now().strftime("%Y-W%U")
|
||||||
scraped_at = menu.get("scraped_at", "unknown")
|
scraped_at = menu.get("scraped_at", "unknown")
|
||||||
submit_url = f"{api_url}/api/submit-order" if api_url else "/api/submit-order"
|
submit_url = (
|
||||||
|
f"{api_url}/api/submit-order" if api_url else "/api/submit-order"
|
||||||
|
).replace("</", "<\\/")
|
||||||
status_url = (
|
status_url = (
|
||||||
f"{api_url}/api/form-status/{week}" if api_url else f"/api/form-status/{week}"
|
f"{api_url}/api/form-status/{week}" if api_url else f"/api/form-status/{week}"
|
||||||
|
).replace("</", "<\\/")
|
||||||
|
roster_url = (f"{api_url}/api/roster" if api_url else "/api/roster").replace(
|
||||||
|
"</", "<\\/"
|
||||||
)
|
)
|
||||||
roster_url = f"{api_url}/api/roster" if api_url else "/api/roster"
|
|
||||||
api_key_json = json.dumps(api_key).replace("</", "<\\/")
|
api_key_json = json.dumps(api_key).replace("</", "<\\/")
|
||||||
has_discount = bulk_discount > 0 or company_subsidy > 0
|
has_discount = bulk_discount > 0 or company_subsidy > 0
|
||||||
use_google_auth = bool(google_client_id)
|
use_google_auth = bool(google_client_id)
|
||||||
|
|
|
||||||
|
|
@ -420,7 +420,7 @@ def test_total_summation_multiple_items(
|
||||||
@patch("submit_order_handler.get_secret", return_value=TEST_API_KEY)
|
@patch("submit_order_handler.get_secret", return_value=TEST_API_KEY)
|
||||||
@patch("submit_order_handler.get_parameter")
|
@patch("submit_order_handler.get_parameter")
|
||||||
@patch("submit_order_handler.get_menu")
|
@patch("submit_order_handler.get_menu")
|
||||||
def test_missing_google_client_id_param_allows_manual_submission(
|
def test_missing_ssm_param_with_env_var_fails_closed(
|
||||||
mock_get_menu,
|
mock_get_menu,
|
||||||
mock_get_parameter,
|
mock_get_parameter,
|
||||||
mock_secret,
|
mock_secret,
|
||||||
|
|
@ -430,7 +430,7 @@ def test_missing_google_client_id_param_allows_manual_submission(
|
||||||
mock_put,
|
mock_put,
|
||||||
mock_lam,
|
mock_lam,
|
||||||
):
|
):
|
||||||
"""Missing Google client ID SSM parameter means auth is not configured."""
|
"""Env var set but SSM param missing -> 503 (fail closed, not silent manual fallback)."""
|
||||||
from submit_order_handler import lambda_handler
|
from submit_order_handler import lambda_handler
|
||||||
|
|
||||||
class ParameterNotFoundError(Exception):
|
class ParameterNotFoundError(Exception):
|
||||||
|
|
@ -448,10 +448,8 @@ def test_missing_google_client_id_param_allows_manual_submission(
|
||||||
|
|
||||||
status, body = _parse_response(result)
|
status, body = _parse_response(result)
|
||||||
|
|
||||||
assert status == 200, f"Expected 200, got {status}: {body}"
|
assert status == 503, f"Expected 503 (fail closed), got {status}: {body}"
|
||||||
saved_order = mock_put.call_args[0][2]
|
mock_put.assert_not_called()
|
||||||
assert saved_order["employee_name"] == "Test User"
|
|
||||||
assert saved_order["employee_email"] == "test.user@seahavenind.com"
|
|
||||||
|
|
||||||
|
|
||||||
@patch("submit_order_handler._lambda")
|
@patch("submit_order_handler._lambda")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue