fix(api): reject explicit null strategy nick
This commit is contained in:
+2
-2
@@ -326,7 +326,7 @@ class StrategyCreateRequest(BaseModel):
|
||||
@classmethod
|
||||
def normalize_nick(cls, value: str | None) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
raise ValueError("nick must not be null")
|
||||
normalized = value.strip()
|
||||
if not normalized:
|
||||
raise ValueError("nick must not be blank")
|
||||
@@ -345,7 +345,7 @@ class StrategyUpdateRequest(BaseModel):
|
||||
@classmethod
|
||||
def normalize_nick(cls, value: str | None) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
raise ValueError("nick must not be null")
|
||||
normalized = value.strip()
|
||||
if not normalized:
|
||||
raise ValueError("nick must not be blank")
|
||||
|
||||
@@ -257,7 +257,7 @@ def test_admin_create_omitting_nick_retains_legacy_generated_value() -> None:
|
||||
assert created.json()["nick"] == expected
|
||||
|
||||
|
||||
def test_admin_create_and_patch_accept_explicit_null_nick() -> None:
|
||||
def test_admin_create_and_patch_reject_explicit_null_nick_without_mutation() -> None:
|
||||
repo = FakeStrategyRepo()
|
||||
with _repos(repo):
|
||||
created = _client().post(
|
||||
@@ -270,9 +270,11 @@ def test_admin_create_and_patch_accept_explicit_null_nick() -> None:
|
||||
json={"nick": None},
|
||||
headers=_auth("admin-token"),
|
||||
)
|
||||
assert created.status_code == 201
|
||||
assert changed.status_code == 200
|
||||
assert created.status_code == 422
|
||||
assert changed.status_code == 422
|
||||
assert set(repo.strategies) == {"active-1", "inactive-1"}
|
||||
assert repo.strategies["active-1"].nick == "target_value:base"
|
||||
assert repo.strategies["active-1"].revision == 1
|
||||
|
||||
|
||||
def test_admin_duplicate_nick_returns_conflict() -> None:
|
||||
|
||||
Reference in New Issue
Block a user