@@ -59,7 +59,7 @@ class GraphQLControllerTest < ActionDispatch::IntegrationTest
5959 "cargoCapacity" => 100000.0 ,
6060 "consumables" => "2 months" ,
6161 "costInCredits" => 100000.0 ,
62- "created_at " => "2014-12-10 16:59:45 UTC" ,
62+ "createdAt " => "2014-12-10 16:59:45 UTC" ,
6363 "crew" => "4" ,
6464 "hyperdriveRating" => 0.5 ,
6565 "length" => 34.37 ,
@@ -75,7 +75,7 @@ class GraphQLControllerTest < ActionDispatch::IntegrationTest
7575 "cargoCapacity" => 10.0 ,
7676 "consumables" => "none" ,
7777 "costInCredits" => nil ,
78- "created_at " => "2014-12-15 12:22:12 UTC" ,
78+ "createdAt " => "2014-12-15 12:22:12 UTC" ,
7979 "crew" => "2" ,
8080 "length" => 4.5 ,
8181 "manufacturer" => "Incom corporation" ,
@@ -109,6 +109,50 @@ class GraphQLControllerTest < ActionDispatch::IntegrationTest
109109 assert_equal expected , JSON . parse ( response . body )
110110 end
111111
112+ test "#execute allows authentication via basic auth" do
113+ query = "" "
114+ {
115+ viewer {
116+ username
117+ }
118+ }
119+ " ""
120+
121+ expected = {
122+ "data" => {
123+ "viewer" => {
124+ "username" => "xuorig"
125+ }
126+ }
127+ }
128+
129+ post graphql_url , params : { query : query } , headers : {
130+ "Authorization" => ActionController ::HttpAuthentication ::Basic . encode_credentials ( "xuorig" , "averysecurepassword" ) ,
131+ }
132+
133+ assert_equal expected , JSON . parse ( response . body )
134+ end
135+
136+ test "#execute authentication is not required" do
137+ query = "" "
138+ {
139+ viewer {
140+ username
141+ }
142+ }
143+ " ""
144+
145+ expected = {
146+ "data" => {
147+ "viewer" => nil
148+ }
149+ }
150+
151+ post graphql_url , params : { query : query }
152+
153+ assert_equal expected , JSON . parse ( response . body )
154+ end
155+
112156 private
113157
114158 def full_graphql_query
@@ -167,7 +211,7 @@ def full_graphql_query
167211 cargoCapacity
168212 consumables
169213 costInCredits
170- created_at
214+ createdAt
171215 crew
172216 hyperdriveRating
173217 length
@@ -183,7 +227,7 @@ def full_graphql_query
183227 cargoCapacity
184228 consumables
185229 costInCredits
186- created_at
230+ createdAt
187231 crew
188232 length
189233 manufacturer
0 commit comments