@@ -827,3 +827,66 @@ def test_query_errors_atomic_request(set_rollback_mock, client):
827
827
def test_query_errors_non_atomic (set_rollback_mock , client ):
828
828
client .get (url_string (query = "force error" ))
829
829
set_rollback_mock .assert_not_called ()
830
+
831
+
832
+ query_with_two_introspections = """
833
+ query Instrospection {
834
+ queryType: __schema {
835
+ queryType {name}
836
+ }
837
+ mutationType: __schema {
838
+ mutationType {name}
839
+ }
840
+ }
841
+ """
842
+
843
+ introspection_disallow_error_message = "introspection is disabled"
844
+ max_validation_errors_exceeded_message = "too many validation errors"
845
+
846
+
847
+ @pytest .mark .urls ("graphene_django.tests.urls_validation" )
848
+ def test_allow_introspection (client ):
849
+ response = client .post (
850
+ url_string ("/graphql/" , query = "{__schema {queryType {name}}}" )
851
+ )
852
+ assert response .status_code == 200
853
+
854
+ assert response_json (response ) == {
855
+ "data" : {"__schema" : {"queryType" : {"name" : "QueryRoot" }}}
856
+ }
857
+
858
+
859
+ @pytest .mark .urls ("graphene_django.tests.urls_validation" )
860
+ def test_validation_disallow_introspection (client ):
861
+ response = client .post (
862
+ url_string ("/graphql/validation/" , query = "{__schema {queryType {name}}}" )
863
+ )
864
+
865
+ assert response .status_code == 400
866
+ assert introspection_disallow_error_message in response .content .decode ()
867
+
868
+
869
+ @pytest .mark .urls ("graphene_django.tests.urls_validation" )
870
+ @patch ("graphene_django.settings.graphene_settings.MAX_VALIDATION_ERRORS" , 2 )
871
+ def test_within_max_validation_errors (client ):
872
+ response = client .post (
873
+ url_string ("/graphql/validation/" , query = query_with_two_introspections )
874
+ )
875
+
876
+ assert response .status_code == 400
877
+
878
+ text_response = response .content .decode ().lower ()
879
+
880
+ assert text_response .count (introspection_disallow_error_message ) == 2
881
+ assert max_validation_errors_exceeded_message not in text_response
882
+
883
+
884
+ @pytest .mark .urls ("graphene_django.tests.urls_validation" )
885
+ @patch ("graphene_django.settings.graphene_settings.MAX_VALIDATION_ERRORS" , 1 )
886
+ def test_exceeds_max_validation_errors (client ):
887
+ response = client .post (
888
+ url_string ("/graphql/validation/" , query = query_with_two_introspections )
889
+ )
890
+
891
+ assert response .status_code == 400
892
+ assert max_validation_errors_exceeded_message in response .content .decode ().lower ()
0 commit comments