@@ -119,4 +119,155 @@ def test_expected_results_with_proper_permissions
119119
120120 assert_equal expected , result . to_h
121121 end
122+
123+ def test_errors_unauthorized_root_field_selections
124+ query = %|{
125+ a1: orderA(id: "1") { shippingAddress }
126+ a2: productA(id: "1") { name }
127+ ...on Query {
128+ b1: orderA(id: "1") { shippingAddress }
129+ b2: productA(id: "1") { description }
130+ ... QueryAttrs
131+ }
132+ }
133+ fragment QueryAttrs on Query {
134+ c1: orderA(id: "1") { shippingAddress }
135+ c2: productA(id: "1") { price }
136+ }|
137+
138+ result = plan_and_execute ( @supergraph , query )
139+ expected = {
140+ "data" => {
141+ "a1" => nil ,
142+ "a2" => nil ,
143+ "b1" => nil ,
144+ "b2" => { "description" => nil } ,
145+ "c1" => nil ,
146+ "c2" => nil ,
147+ } ,
148+ "errors" => [ {
149+ "message" => "Unauthorized access" ,
150+ "path" => [ "a1" ] ,
151+ "extensions" => { "code" => "unauthorized" } ,
152+ } , {
153+ "message" => "Unauthorized access" ,
154+ "path" => [ "b1" ] ,
155+ "extensions" => { "code" => "unauthorized" } ,
156+ } , {
157+ "message" => "Unauthorized access" ,
158+ "path" => [ "c1" ] ,
159+ "extensions" => { "code" => "unauthorized" } ,
160+ } , {
161+ "message" => "Unauthorized access" ,
162+ "path" => [ "a2" , "name" ] ,
163+ "extensions" => { "code" => "unauthorized" } ,
164+ } , {
165+ "message" => "Unauthorized access" ,
166+ "path" => [ "b2" , "description" ] ,
167+ "extensions" => { "code" => "unauthorized" } ,
168+ } , {
169+ "message" => "Unauthorized access" ,
170+ "path" => [ "c2" , "price" ] ,
171+ "extensions" => { "code" => "unauthorized" } ,
172+ } ] ,
173+ }
174+
175+ assert_equal expected , result . to_h
176+ end
177+
178+ def test_stitches_around_unauthorized_access
179+ query = %|{
180+ orderA(id: "1") {
181+ open
182+ customer1 {
183+ email
184+ }
185+ customer2 {
186+ email
187+ }
188+ product {
189+ description
190+ open
191+ }
192+ }
193+ }|
194+
195+ result = plan_and_execute ( @supergraph , query , claims : [ "orders" ] )
196+ expected = {
197+ "data" => {
198+ "orderA" => {
199+ "open" => true ,
200+ "customer1" => nil ,
201+ "customer2" => nil ,
202+ "product" => {
203+ "description" => nil ,
204+ "open" => true ,
205+ }
206+ }
207+ } ,
208+ "errors" => [ {
209+ "message" => "Unauthorized access" ,
210+ "path" => [ "orderA" , "customer1" , "email" ] ,
211+ "extensions" => { "code" => "unauthorized" } ,
212+ } , {
213+ "message" => "Unauthorized access" ,
214+ "path" => [ "orderA" , "customer2" ] ,
215+ "extensions" => { "code" => "unauthorized" } ,
216+ } , {
217+ "message" => "Unauthorized access" ,
218+ "path" => [ "orderA" , "product" , "description" ] ,
219+ "extensions" => { "code" => "unauthorized" } ,
220+ } ] ,
221+ }
222+
223+ assert_equal expected , result . to_h
224+ end
225+
226+ def test_stitches_around_unauthorized_access_from_opposing_entrypoint
227+ query = %|{
228+ orderB(id: "1") {
229+ open
230+ customer1 {
231+ email
232+ }
233+ customer2 {
234+ email
235+ }
236+ product {
237+ description
238+ open
239+ }
240+ }
241+ }|
242+
243+ result = plan_and_execute ( @supergraph , query , claims : [ "orders" ] )
244+ expected = {
245+ "data" => {
246+ "orderB" => {
247+ "open" => true ,
248+ "customer1" => nil ,
249+ "customer2" => nil ,
250+ "product" => {
251+ "description" => nil ,
252+ "open" => true ,
253+ }
254+ }
255+ } ,
256+ "errors" => [ {
257+ "message" => "Unauthorized access" ,
258+ "path" => [ "orderB" , "customer2" ] ,
259+ "extensions" => { "code" => "unauthorized" } ,
260+ } , {
261+ "message" => "Unauthorized access" ,
262+ "path" => [ "orderB" , "customer1" , "email" ] ,
263+ "extensions" => { "code" => "unauthorized" } ,
264+ } , {
265+ "message" => "Unauthorized access" ,
266+ "path" => [ "orderB" , "product" , "description" ] ,
267+ "extensions" => { "code" => "unauthorized" } ,
268+ } ] ,
269+ }
270+
271+ assert_equal expected , result . to_h
272+ end
122273end
0 commit comments