Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

70 lines
2.4 KiB
Python

"""Tests for news API input validation (PR #1939).
Verifies:
- Limit parameter clamped to [1, 200]
- JSON body validation via @require_json_body decorator
"""
import inspect
class TestLimitClamping:
"""Verify limit parameters are clamped to safe range."""
def test_get_news_feed_clamps_limit(self):
from local_deep_research.web.routes.news_routes import get_news_feed
source = inspect.getsource(get_news_feed)
assert "max(1, min(limit, 200))" in source
def test_get_subscription_history_clamps_limit(self):
from local_deep_research.web.routes.news_routes import (
get_subscription_history,
)
source = inspect.getsource(get_subscription_history)
assert "max(1, min(limit, 200))" in source
class TestJSONBodyValidation:
"""Verify endpoints reject missing/empty JSON body.
These endpoints use the @require_json_body decorator which validates
that the request body is a JSON dict before the handler runs.
"""
def _check_has_json_guard(self, func_name):
"""Verify the endpoint is protected by @require_json_body."""
import local_deep_research.web.routes.news_routes as mod
func = getattr(mod, func_name)
# The decorator wraps the function, so check the decorator chain.
# inspect.getsource on the module-level function includes decorators.
source = inspect.getsource(func)
# Either protected by @require_json_body decorator or inline check
has_decorator = "@require_json_body" in source
has_inline = (
"if data is None" in source or "if preferences is None" in source
)
assert has_decorator or has_inline, (
f"{func_name} is missing JSON body validation — "
f"add @require_json_body or an inline 'if data is None' check"
)
def test_create_subscription_validates_json(self):
self._check_has_json_guard("create_subscription")
def test_update_subscription_validates_json(self):
self._check_has_json_guard("update_subscription")
def test_submit_feedback_validates_json(self):
self._check_has_json_guard("submit_feedback")
def test_research_news_item_validates_json(self):
self._check_has_json_guard("research_news_item")
def test_save_preferences_validates_json(self):
self._check_has_json_guard("save_preferences")