Skip to content

Commit 802b431

Browse files
committed
Address PR #1373 review: fix CI test failure + drop redundant comments
Test fix: graphql_jwt's @login_required wrapper requires a ResolveInfo arg (uses isinstance check). Spec the MagicMock with ResolveInfo so the decorator passes through to the wrapped guard. Imported ResolveInfo from graphene (not graphql). Style: dropped two inline 'subclasses must override' comments on IOSettings fields. The ClassVar[Optional[type[...]]] = None annotation already signals the intent and _require_io_setting documents the guard.
1 parent 25f5dab commit 802b431

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

config/graphql/base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def resolve_total_count(root, info, **kwargs):
8686
class DRFDeletion(graphene.Mutation):
8787
class IOSettings(ABC):
8888
lookup_field: ClassVar[str] = "id"
89-
# Concrete subclasses must override ``model`` with their Django model;
90-
# see ``_require_io_setting`` for the runtime guard.
9189
model: ClassVar[Optional[type[django.db.models.Model]]] = None
9290

9391
class Arguments:
@@ -148,8 +146,6 @@ class DRFMutation(graphene.Mutation):
148146
class IOSettings(ABC):
149147
pk_fields: ClassVar[list[str]] = []
150148
lookup_field: ClassVar[str] = "id"
151-
# Concrete subclasses must override ``model``, ``graphene_model`` and
152-
# ``serializer``; see ``_require_io_setting`` for the runtime guard.
153149
model: ClassVar[Optional[type[django.db.models.Model]]] = None
154150
graphene_model: ClassVar[Optional[type[DjangoObjectType]]] = None
155151
serializer: ClassVar[Optional[type[serializers.Serializer]]] = None

opencontractserver/tests/test_security_hardening.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,14 +1264,20 @@ def test_drf_deletion_mutate_raises_when_lookup_value_missing(self):
12641264
"""``DRFDeletion.mutate`` must raise ``ValueError`` when the lookup arg is omitted."""
12651265
from unittest.mock import MagicMock
12661266

1267+
from graphene import ResolveInfo
1268+
12671269
from config.graphql.base import DRFDeletion
12681270

12691271
class _DeleteCorpus(DRFDeletion):
12701272
class IOSettings(DRFDeletion.IOSettings):
12711273
model = Corpus
12721274
lookup_field = "id"
12731275

1274-
info = MagicMock()
1276+
# ``@login_required`` from graphql_jwt looks for a ``ResolveInfo`` arg
1277+
# via ``isinstance``; spec the mock so the decorator passes through
1278+
# to the wrapped function where the real lookup-value check fires.
1279+
info = MagicMock(spec=ResolveInfo)
1280+
info.context = MagicMock()
12751281
info.context.user = MagicMock(is_authenticated=True)
12761282

12771283
with self.assertRaises(ValueError) as ctx:

0 commit comments

Comments
 (0)