forked from retoor/devplacepy
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8ed5b690f |
File diff suppressed because one or more lines are too long
+12
-2
@@ -439,8 +439,8 @@ class VoteForm(BaseModel):
|
||||
@field_validator("value")
|
||||
@classmethod
|
||||
def valid_value(cls, value):
|
||||
if value not in (1, -1, 0):
|
||||
raise ValueError("value must be 1, -1, or 0")
|
||||
if value not in (1, -1):
|
||||
raise ValueError("value must be 1 or -1")
|
||||
return value
|
||||
|
||||
|
||||
@@ -470,9 +470,19 @@ class SeoRunForm(BaseModel):
|
||||
text = value.strip()
|
||||
if not text:
|
||||
raise ValueError("A URL is required")
|
||||
if "://" in text:
|
||||
scheme = text.split("://", 1)[0]
|
||||
if scheme not in ("http", "https"):
|
||||
raise ValueError(f"Only http and https URLs are allowed; got '{scheme}://'")
|
||||
else:
|
||||
text = f"https://{text}"
|
||||
if not SEO_URL_PATTERN.match(text):
|
||||
raise ValueError("URL must be a valid http or https source location")
|
||||
return text
|
||||
|
||||
|
||||
SEO_URL_PATTERN = re.compile(r"^https?://[a-zA-Z0-9][\w./:@~^?&#%=;-]*$")
|
||||
|
||||
ISSLOP_URL_PATTERN = re.compile(r"^(https?://|git://|ssh://|git@)[\w./:@~^-]+$", re.IGNORECASE)
|
||||
ISSLOP_SINGLE_SLASH_PATTERN = re.compile(r"^(https?|git|ssh):/(?!/)", re.IGNORECASE)
|
||||
ISSLOP_SCHEME_PATTERN = re.compile(r"^[a-z][a-z0-9+.-]*://", re.IGNORECASE)
|
||||
|
||||
@@ -22,7 +22,7 @@ ENGAGEMENT_ACTIONS: tuple[Action, ...] = (
|
||||
),
|
||||
body(
|
||||
"value",
|
||||
"Vote value: 1 to upvote, -1 to downvote, 0 to retract.",
|
||||
"Vote value: 1 to upvote, -1 to downvote (re-send to remove).",
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -89,6 +89,53 @@ def test_run_clamps_max_pages_above_cap(app_server):
|
||||
_clear_seo_jobs()
|
||||
|
||||
|
||||
def test_run_rejects_malformed_scheme(app_server):
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/tools/seo/run",
|
||||
headers=_json_headers(),
|
||||
data={"url": "ahttps://devplace.net/sitem", "mode": "url"},
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert r.status_code in (400, 422), r.text
|
||||
|
||||
|
||||
def test_run_rejects_relative_path(app_server):
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/tools/seo/run",
|
||||
headers=_json_headers(),
|
||||
data={"url": "/feed", "mode": "url"},
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert r.status_code in (400, 422), r.text
|
||||
|
||||
|
||||
def test_run_normalizes_missing_scheme(app_server):
|
||||
try:
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/tools/seo/run",
|
||||
headers=_json_headers(),
|
||||
data={"url": "example.com", "mode": "url", "max_pages": "5"},
|
||||
)
|
||||
assert r.status_code == 200, r.text
|
||||
uid = r.json()["uid"]
|
||||
refresh_snapshot()
|
||||
job = queue.get_job(uid)
|
||||
assert job is not None
|
||||
assert job["payload"]["url"] == "https://example.com"
|
||||
finally:
|
||||
_clear_seo_jobs()
|
||||
|
||||
|
||||
def test_run_rejects_non_http_scheme(app_server):
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/tools/seo/run",
|
||||
headers=_json_headers(),
|
||||
data={"url": "ftp://example.com", "mode": "url"},
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert r.status_code in (400, 422), r.text
|
||||
|
||||
|
||||
def test_run_enforces_one_active_job_per_owner(app_server):
|
||||
try:
|
||||
first = requests.post(
|
||||
|
||||
@@ -135,13 +135,3 @@ def test_non_ajax_vote_redirects_to_referer(app_server):
|
||||
)
|
||||
assert r.status_code == 302
|
||||
assert r.headers["location"] == "/gists"
|
||||
|
||||
|
||||
def test_explicit_zero_retracts_vote(app_server):
|
||||
s_a, a_name = _session_votes()
|
||||
s_b, _ = _session_votes()
|
||||
post_uid = _make_post_votes(_uid_votes(a_name))
|
||||
s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
|
||||
r = s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "0"}, headers=AJAX_votes)
|
||||
assert r.json()["value"] == 0
|
||||
assert r.json()["net"] == 0
|
||||
|
||||
Reference in New Issue
Block a user