-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: disable graphql introspection queries
GraphQL queries starting with `__` e.g. `__schema` will be disabled by default. Refs: HP-2350
- Loading branch information
Showing
6 changed files
with
69 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ Prerequisites: | |
* `CREATE_SUPERUSER`, creates a superuser with credentials `admin`:`admin` ([email protected]) | ||
* `APPLY_MIGRATIONS`, applies migrations on startup | ||
* `ENABLE_GRAPHIQL`, enables GraphiQL interface for `/graphql/` | ||
* `ENABLE_GRAPHQL_INTROSPECTION`, enables GraphQL introspection queries | ||
* `SEED_DEVELOPMENT_DATA`, flush data and recreate the environment with | ||
fake development data (requires `APPLY_MIGRATIONS`) | ||
* `OIDC_CLIENT_ID`, Tunnistamo client id for enabling GDPR API authorization code flows | ||
|
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
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 |
---|---|---|
@@ -1,7 +1,32 @@ | ||
from graphql import print_schema | ||
import pytest | ||
import requests | ||
from graphql import get_introspection_query, print_schema | ||
|
||
|
||
def test_graphql_schema_matches_the_reference(gql_schema, snapshot): | ||
actual_schema = print_schema(gql_schema) | ||
|
||
snapshot.assert_match(actual_schema) | ||
|
||
|
||
@pytest.mark.parametrize("enabled", [True, False]) | ||
def test_graphql_schema_introspection_can_be_disabled(live_server, settings, enabled): | ||
settings.ENABLE_GRAPHQL_INTROSPECTION = enabled | ||
url = live_server.url + "/graphql/" | ||
payload = { | ||
"query": get_introspection_query(), | ||
} | ||
|
||
response = requests.post(url, json=payload) | ||
|
||
body = response.json() | ||
if enabled: | ||
assert response.status_code == 200 | ||
assert "errors" not in body | ||
assert "__schema" in body["data"] | ||
else: | ||
assert response.status_code == 400 | ||
assert "data" not in body | ||
error = body["errors"][0]["message"] | ||
assert "__schema" in error | ||
assert "introspection is disabled" in error |
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