-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Prevent a possible security issue when resolving a relay model w…
…ith multiple possibilities Follow up to the security fix on Strawberry, which requires changes to this integration as well.
- Loading branch information
1 parent
a30755f
commit d1a3e94
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
import strawberry | ||
from strawberry import relay | ||
|
||
import strawberry_django | ||
from tests.projects.models import Project | ||
|
||
|
||
@pytest.mark.parametrize("type_name", ["ProjectType", "PublicProjectObject"]) | ||
@pytest.mark.django_db(transaction=True) | ||
def test_correct_model_returned(type_name: str): | ||
@strawberry_django.type(Project) | ||
class ProjectType(relay.Node): | ||
name: relay.NodeID[str] | ||
due_date: strawberry.auto | ||
|
||
@strawberry_django.type(Project) | ||
class PublicProjectObject(relay.Node): | ||
name: relay.NodeID[str] | ||
due_date: strawberry.auto | ||
|
||
@strawberry.type | ||
class Query: | ||
node: relay.Node = relay.node() | ||
|
||
schema = strawberry.Schema(query=Query, types=[ProjectType, PublicProjectObject]) | ||
Project.objects.create(name="test") | ||
|
||
node_id = relay.to_base64(type_name, "test") | ||
result = schema.execute_sync( | ||
""" | ||
query NodeQuery($id: GlobalID!) { | ||
node(id: $id) { | ||
__typename | ||
id | ||
} | ||
} | ||
""", | ||
{"id": node_id}, | ||
) | ||
assert result.errors is None | ||
assert result.data == {"node": {"__typename": type_name, "id": node_id}} |