Skip to content
Merged
Changes from all 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
14 changes: 4 additions & 10 deletions src/mock_vws/_model_target_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import secrets
import uuid
import zipfile
from collections.abc import Mapping
from http import HTTPStatus
from typing import Any, Protocol, TypeGuard, runtime_checkable
from urllib.parse import parse_qs
Expand Down Expand Up @@ -93,11 +92,6 @@ def remove_oauth2_client_credential(self, client_id: str) -> None:
_MAX_CLIENT_CREDENTIALS = 100


def _is_object_mapping(value: object, /) -> TypeGuard[Mapping[object, object]]:
"""Return whether a value is a mapping with unchecked entries."""
return isinstance(value, Mapping)


# A stable mock value standing in for the user-id segment that real
# Vuforia embeds in some Model Target error targets such as
# ``userId:7635391``. The numeric portion is per-account in real Vuforia;
Expand Down Expand Up @@ -300,7 +294,7 @@ def _jwt_header_error(*, bearer_token: str) -> str | None:


@beartype
def _jwt_payload(*, bearer_token: str) -> tuple[Mapping[object, object], bool]:
def _jwt_payload(*, bearer_token: str) -> tuple[dict[str, JSONValue], bool]:
"""Decode a JSON Web Token payload and report whether it is an
object.
"""
Expand All @@ -316,8 +310,8 @@ def _jwt_payload(*, bearer_token: str) -> tuple[Mapping[object, object], bool]:
except ValueError:
payload = None

if not _is_object_mapping(payload):
return dict[object, object](), False
if not _is_json_object(payload):
return {}, False
return payload, True


Expand Down Expand Up @@ -357,7 +351,7 @@ def _jwt_scopes(*, bearer_token: str) -> frozenset[str]:
"""Return scopes from a valid mock JSON Web Token."""
empty_scopes = frozenset[str]()
payload, _ = _jwt_payload(bearer_token=bearer_token)
scope: object = payload.get("scope", "")
scope = payload.get("scope", "")
if not isinstance(scope, str):
return empty_scopes
return frozenset(scope.split())
Expand Down
Loading