Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: confluent API spec evolution #925

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion karapace/schema_registry_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ def _validate_schema_request_body(self, content_type: str, body: dict | Any) ->
status=HTTPStatus.BAD_REQUEST,
)
for field in body:
if field not in {"schema", "schemaType", "references"}:
if field not in {"schema", "schemaType", "references", "metadata", "ruleSet"}:
self.r(
body={
"error_code": SchemaErrorCodes.HTTP_UNPROCESSABLE_ENTITY.value,
Expand Down
13 changes: 12 additions & 1 deletion tests/integration/schema_registry/test_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
TYPES_STRING_SCHEMA,
)
from tests.utils import new_random_name
from typing import Any, Dict

import json
import pytest
Expand Down Expand Up @@ -234,8 +235,14 @@ async def not_schemas_are_backward_compatible(

@pytest.mark.parametrize("trail", ["", "/"])
@pytest.mark.parametrize("compatibility", [CompatibilityModes.FORWARD, CompatibilityModes.BACKWARD, CompatibilityModes.FULL])
@pytest.mark.parametrize("metadata", [None, {}])
@pytest.mark.parametrize("rule_set", [None, {}])
async def test_same_jsonschema_must_have_same_id(
registry_async_client: Client, compatibility: CompatibilityModes, trail: str
registry_async_client: Client,
compatibility: CompatibilityModes,
trail: str,
metadata: Dict[str, Any],
nosahama marked this conversation as resolved.
Show resolved Hide resolved
rule_set: Dict[str, Any],
) -> None:
for schema in ALL_SCHEMAS:
subject = new_random_name("subject")
Expand All @@ -248,6 +255,8 @@ async def test_same_jsonschema_must_have_same_id(
json={
"schema": json.dumps(schema.schema),
"schemaType": SchemaType.JSONSCHEMA.value,
"metadata": metadata,
"ruleSet": rule_set,
},
)
assert first_res.status_code == 200
Expand All @@ -259,6 +268,8 @@ async def test_same_jsonschema_must_have_same_id(
json={
"schema": json.dumps(schema.schema),
"schemaType": SchemaType.JSONSCHEMA.value,
"metadata": metadata,
"ruleSet": rule_set,
},
)
assert second_res.status_code == 200
Expand Down
15 changes: 12 additions & 3 deletions tests/integration/test_schema_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from karapace.typing import JsonData
from tests.base_testcase import BaseTestCase
from tests.utils import create_subject_name_factory
from typing import List, Optional, Union
from typing import Any, Dict, List, Optional, Union

import logging
import pytest
Expand Down Expand Up @@ -963,11 +963,20 @@ class ReferenceTestCase(BaseTestCase):
],
ids=str,
)
async def test_references(testcase: ReferenceTestCase, registry_async_client: Client):
@pytest.mark.parametrize("metadata", [None, {}])
@pytest.mark.parametrize("rule_set", [None, {}])
async def test_references(
testcase: ReferenceTestCase, registry_async_client: Client, metadata: Dict[str, Any], rule_set: Dict[str, Any]
):
for testdata in testcase.schemas:
if isinstance(testdata, TestCaseSchema):
print(f"Adding new schema, subject: '{testdata.subject}'\n{testdata.schema_str}")
body = {"schemaType": testdata.schema_type, "schema": testdata.schema_str}
body = {
"schemaType": testdata.schema_type,
"schema": testdata.schema_str,
"metadata": metadata,
"ruleSet": rule_set,
}
if testdata.references:
body["references"] = testdata.references
res = await registry_async_client.post(f"subjects/{testdata.subject}/versions", json=body)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_schema_registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
from unittest.mock import ANY, AsyncMock, Mock, patch, PropertyMock

import asyncio
import pytest


async def test_validate_schema_request_body():
controller = KarapaceSchemaRegistryController(config=set_config_defaults(DEFAULTS))

controller._validate_schema_request_body( # pylint: disable=W0212
"application/json", {"schema": "{}", "schemaType": "JSON", "references": [], "metadata": {}, "ruleSet": {}}
)

with pytest.raises(HTTPResponse) as exc_info:
controller._validate_schema_request_body( # pylint: disable=W0212
"application/json",
{"schema": "{}", "schemaType": "JSON", "references": [], "unexpected_field_name": {}, "ruleSet": {}},
)
assert exc_info.type is HTTPResponse
assert str(exc_info.value) == "HTTPResponse 422"


async def test_forward_when_not_ready():
Expand Down
Loading