Skip to content

Commit

Permalink
Merge pull request #409 from aiven/fix-subject-name-escaping
Browse files Browse the repository at this point in the history
Fix subject name escaping
  • Loading branch information
HelenMel authored Jul 6, 2022
2 parents 72779bd + ea7e972 commit c8679d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion karapace/schema_registry_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def send_schema_message(
version: int,
deleted: bool,
):
key = '{{"subject":"{}","version":{},"magic":1,"keytype":"SCHEMA"}}'.format(subject, version)
key = json.dumps({"subject": subject, "version": version, "magic": 1, "keytype": "SCHEMA"}, separators=(",", ":"))
if schema:
valuedict = {
"subject": subject,
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ async def test_missing_subject_compatibility(registry_async_client: Client, trai
assert "compatibilityLevel" in res.json(), res.json()


async def test_subject_allowed_chars(registry_async_client: Client) -> None:
subject_prefix = create_subject_name_factory("test_subject_allowed_chars-")()

for suffix in ['"', "{", ":", "}", "'"]:
subject = f"{subject_prefix}{suffix}"
res = await registry_async_client.post(
f"subjects/{subject}/versions", json={"schema": json.dumps({"type": "string"})}
)
assert res.status_code == 200, f"{res} {subject}"


@pytest.mark.parametrize("trail", ["", "/"])
async def test_record_union_schema_compatibility(registry_async_client: Client, trail: str) -> None:
subject = create_subject_name_factory(f"test_record_union_schema_compatibility-{trail}")()
Expand Down

0 comments on commit c8679d2

Please sign in to comment.