We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -45,6 +45,6 @@ |
||
45 | 45 | |
46 | 46 | protected function normalizeFields(array $fields): array |
47 | 47 | { |
48 | - return array_map(fn (array $field) => new Field($field), $fields); |
|
48 | + return array_map(fn(array $field) => new Field($field), $fields); |
|
49 | 49 | } |
50 | 50 | } |
@@ -45,6 +45,6 @@ |
||
45 | 45 | |
46 | 46 | protected function normalizeArgs(array $args): array |
47 | 47 | { |
48 | - return array_map(fn (array $arg) => new Arg($arg), $args); |
|
48 | + return array_map(fn(array $arg) => new Arg($arg), $args); |
|
49 | 49 | } |
50 | 50 | } |
@@ -311,12 +311,12 @@ |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | if (!empty($this->config->interfaces)) { |
314 | - $items = array_map(fn ($type) => "$this->gqlServices->getType('$type')", $this->config->interfaces); |
|
314 | + $items = array_map(fn($type) => "$this->gqlServices->getType('$type')", $this->config->interfaces); |
|
315 | 315 | $configLoader->addItem('interfaces', ArrowFunction::new(Collection::numeric($items, true))); |
316 | 316 | } |
317 | 317 | |
318 | 318 | if (!empty($this->config->types)) { |
319 | - $items = array_map(fn ($type) => "$this->gqlServices->getType('$type')", $this->config->types); |
|
319 | + $items = array_map(fn($type) => "$this->gqlServices->getType('$type')", $this->config->types); |
|
320 | 320 | $configLoader->addItem('types', ArrowFunction::new(Collection::numeric($items, true))); |
321 | 321 | } |
322 | 322 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $node |
43 | 43 | ->isRequired() |
44 | 44 | ->validate() |
45 | - ->ifTrue(fn ($name) => !preg_match('/^[_a-z][_0-9a-z]*$/i', $name)) |
|
45 | + ->ifTrue(fn($name) => !preg_match('/^[_a-z][_0-9a-z]*$/i', $name)) |
|
46 | 46 | ->thenInvalid('Invalid type name "%s". (see http://spec.graphql.org/June2018/#sec-Names)') |
47 | 47 | ->end() |
48 | 48 | ; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | { |
158 | 158 | $node |
159 | 159 | ->beforeNormalization() |
160 | - ->ifTrue(fn ($options) => !empty($options[$old]) && empty($options[$new])) |
|
160 | + ->ifTrue(fn($options) => !empty($options[$old]) && empty($options[$new])) |
|
161 | 161 | ->then(function ($options) use ($old, $new) { |
162 | 162 | if (is_callable($options[$old])) { |
163 | 163 | if (is_array($options[$old])) { |
@@ -167,8 +167,7 @@ discard block |
||
167 | 167 | } |
168 | 168 | } elseif (is_string($options[$old])) { |
169 | 169 | $options[$new]['expression'] = ExpressionLanguage::stringHasTrigger($options[$old]) ? |
170 | - ExpressionLanguage::unprefixExpression($options[$old]) : |
|
171 | - json_encode($options[$old]); |
|
170 | + ExpressionLanguage::unprefixExpression($options[$old]) : json_encode($options[$old]); |
|
172 | 171 | } else { |
173 | 172 | $options[$new]['expression'] = json_encode($options[$old]); |
174 | 173 | } |
@@ -177,7 +176,7 @@ discard block |
||
177 | 176 | }) |
178 | 177 | ->end() |
179 | 178 | ->beforeNormalization() |
180 | - ->ifTrue(fn ($options) => is_array($options) && array_key_exists($old, $options)) |
|
179 | + ->ifTrue(fn($options) => is_array($options) && array_key_exists($old, $options)) |
|
181 | 180 | ->then(function ($options) use ($old) { |
182 | 181 | unset($options[$old]); |
183 | 182 | |
@@ -185,7 +184,7 @@ discard block |
||
185 | 184 | }) |
186 | 185 | ->end() |
187 | 186 | ->validate() |
188 | - ->ifTrue(fn (array $v) => !empty($v[$new]) && !empty($v[$old])) |
|
187 | + ->ifTrue(fn(array $v) => !empty($v[$new]) && !empty($v[$old])) |
|
189 | 188 | ->thenInvalid(sprintf( |
190 | 189 | '"%s" and "%s" should not be used together in "%%s".', |
191 | 190 | $new, |
@@ -203,21 +202,21 @@ discard block |
||
203 | 202 | $node |
204 | 203 | ->info($info) |
205 | 204 | ->validate() |
206 | - ->ifTrue(fn (array $v) => !empty($v['method']) && !empty($v['expression'])) |
|
205 | + ->ifTrue(fn(array $v) => !empty($v['method']) && !empty($v['expression'])) |
|
207 | 206 | ->thenInvalid('"method" and "expression" should not be use together.') |
208 | 207 | ->end() |
209 | 208 | ->beforeNormalization() |
210 | 209 | // Allow short syntax |
211 | - ->ifTrue(fn ($options) => is_string($options) && ExpressionLanguage::stringHasTrigger($options)) |
|
212 | - ->then(fn ($options) => ['expression' => ExpressionLanguage::unprefixExpression($options)]) |
|
210 | + ->ifTrue(fn($options) => is_string($options) && ExpressionLanguage::stringHasTrigger($options)) |
|
211 | + ->then(fn($options) => ['expression' => ExpressionLanguage::unprefixExpression($options)]) |
|
213 | 212 | ->end() |
214 | 213 | ->beforeNormalization() |
215 | - ->ifTrue(fn ($options) => is_string($options) && !ExpressionLanguage::stringHasTrigger($options)) |
|
216 | - ->then(fn ($options) => ['method' => $options]) |
|
214 | + ->ifTrue(fn($options) => is_string($options) && !ExpressionLanguage::stringHasTrigger($options)) |
|
215 | + ->then(fn($options) => ['method' => $options]) |
|
217 | 216 | ->end() |
218 | 217 | ->beforeNormalization() |
219 | 218 | // clean expression |
220 | - ->ifTrue(fn ($options) => isset($options['expression']) && is_string($options['expression']) && ExpressionLanguage::stringHasTrigger($options['expression'])) |
|
219 | + ->ifTrue(fn($options) => isset($options['expression']) && is_string($options['expression']) && ExpressionLanguage::stringHasTrigger($options['expression'])) |
|
221 | 220 | ->then(function ($options) { |
222 | 221 | $options['expression'] = ExpressionLanguage::unprefixExpression($options['expression']); |
223 | 222 |
@@ -14,8 +14,8 @@ |
||
14 | 14 | { |
15 | 15 | parent::__construct( |
16 | 16 | 'getUser', |
17 | - fn () => "$this->gqlServices->get('".Security::class."')->getUser()", |
|
18 | - static fn (array $arguments) => $arguments[TypeGenerator::GRAPHQL_SERVICES]->get(Security::class)->getUser() |
|
17 | + fn() => "$this->gqlServices->get('".Security::class."')->getUser()", |
|
18 | + static fn(array $arguments) => $arguments[TypeGenerator::GRAPHQL_SERVICES]->get(Security::class)->getUser() |
|
19 | 19 | ); |
20 | 20 | } |
21 | 21 | } |
@@ -14,8 +14,8 @@ |
||
14 | 14 | { |
15 | 15 | parent::__construct( |
16 | 16 | 'isAnonymous', |
17 | - fn () => "$this->gqlServices->get('".Security::class."')->isAnonymous()", |
|
18 | - static fn (array $arguments) => $arguments[TypeGenerator::GRAPHQL_SERVICES]->get(Security::class)->isAnonymous() |
|
17 | + fn() => "$this->gqlServices->get('".Security::class."')->isAnonymous()", |
|
18 | + static fn(array $arguments) => $arguments[TypeGenerator::GRAPHQL_SERVICES]->get(Security::class)->isAnonymous() |
|
19 | 19 | ); |
20 | 20 | } |
21 | 21 | } |
@@ -14,8 +14,8 @@ |
||
14 | 14 | { |
15 | 15 | parent::__construct( |
16 | 16 | 'isRememberMe', |
17 | - fn () => "$this->gqlServices->get('".Security::class."')->isRememberMe()", |
|
18 | - static fn (array $arguments) => $arguments[TypeGenerator::GRAPHQL_SERVICES]->get(Security::class)->isRememberMe() |
|
17 | + fn() => "$this->gqlServices->get('".Security::class."')->isRememberMe()", |
|
18 | + static fn(array $arguments) => $arguments[TypeGenerator::GRAPHQL_SERVICES]->get(Security::class)->isRememberMe() |
|
19 | 19 | ); |
20 | 20 | } |
21 | 21 | } |
@@ -26,343 +26,3 @@ |
||
26 | 26 | private string $userIsEnabledQuery = 'query ($hasAccess: Boolean = true) { user { isEnabled(hasAccess: $hasAccess) } }'; |
27 | 27 | |
28 | 28 | private string $userFriendsQuery = <<<'QUERY' |
29 | - query { |
|
30 | - user { |
|
31 | - friends(first: 2) { |
|
32 | - edges { |
|
33 | - node { |
|
34 | - name |
|
35 | - } |
|
36 | - } |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - QUERY; |
|
41 | - |
|
42 | - private string $simpleMutationWithThunkQuery = <<<'MUTATION' |
|
43 | - mutation M { |
|
44 | - simpleMutationWithThunkFields(input: {inputData: %d, clientMutationId: "bac"}) { |
|
45 | - result |
|
46 | - clientMutationId |
|
47 | - } |
|
48 | - } |
|
49 | - MUTATION; |
|
50 | - |
|
51 | - public function setUp(): void |
|
52 | - { |
|
53 | - parent::setUp(); |
|
54 | - // load types |
|
55 | - $this->loader = function ($class): void { |
|
56 | - if (preg_match('@^'.preg_quote('Overblog\GraphQLBundle\Access\__DEFINITIONS__\\').'(.*)$@', $class, $matches)) { |
|
57 | - $file = sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/access/cache/testaccess/overblog/graphql-bundle/__definitions__/'.$matches[1].'.php'; |
|
58 | - if (file_exists($file)) { |
|
59 | - require $file; |
|
60 | - } |
|
61 | - } |
|
62 | - }; |
|
63 | - spl_autoload_register($this->loader); |
|
64 | - } |
|
65 | - |
|
66 | - public function testCustomClassLoaderNotRegister(): void |
|
67 | - { |
|
68 | - $this->expectException(Error::class); |
|
69 | - if ((int) phpversion() <= 7) { |
|
70 | - $this->expectExceptionMessage('Class \'Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType\' not found'); |
|
71 | - } else { |
|
72 | - $this->expectExceptionMessage('Class "Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType" not found'); |
|
73 | - } |
|
74 | - spl_autoload_unregister($this->loader); |
|
75 | - $this->assertResponse($this->userNameQuery, [], static::ANONYMOUS_USER, 'access'); |
|
76 | - } |
|
77 | - |
|
78 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledTrue(): void |
|
79 | - { |
|
80 | - $this->assertResponse( |
|
81 | - $this->userIsEnabledQuery, |
|
82 | - ['data' => ['user' => ['isEnabled' => true]]], |
|
83 | - static::ANONYMOUS_USER, |
|
84 | - 'access' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledFalse(): void |
|
89 | - { |
|
90 | - $this->assertResponse( |
|
91 | - $this->userIsEnabledQuery, |
|
92 | - [ |
|
93 | - 'data' => [ |
|
94 | - 'user' => [ |
|
95 | - 'isEnabled' => null, |
|
96 | - ], |
|
97 | - ], |
|
98 | - 'extensions' => [ |
|
99 | - 'warnings' => [ |
|
100 | - [ |
|
101 | - 'message' => 'Access denied to this field.', |
|
102 | - 'locations' => [['line' => 1, 'column' => 45]], |
|
103 | - 'path' => ['user', 'isEnabled'], |
|
104 | - ], |
|
105 | - ], |
|
106 | - ], |
|
107 | - ], |
|
108 | - static::ANONYMOUS_USER, |
|
109 | - 'access', |
|
110 | - '', |
|
111 | - ['hasAccess' => false] |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - public function testNotAuthenticatedUserAccessToUserName(): void |
|
116 | - { |
|
117 | - $expected = [ |
|
118 | - 'data' => [ |
|
119 | - 'user' => [ |
|
120 | - 'name' => null, |
|
121 | - ], |
|
122 | - ], |
|
123 | - 'extensions' => [ |
|
124 | - 'warnings' => [ |
|
125 | - [ |
|
126 | - 'message' => 'Access denied to this field.', |
|
127 | - 'locations' => [['line' => 1, 'column' => 16]], |
|
128 | - 'path' => ['user', 'name'], |
|
129 | - ], |
|
130 | - ], |
|
131 | - ], |
|
132 | - ]; |
|
133 | - |
|
134 | - $this->assertResponse($this->userNameQuery, $expected, static::ANONYMOUS_USER, 'access'); |
|
135 | - } |
|
136 | - |
|
137 | - public function testNonAuthenticatedUserAccessSecuredFieldWhichInitiallyResolvesToArray(): void |
|
138 | - { |
|
139 | - $expected = [ |
|
140 | - 'data' => [ |
|
141 | - 'youShallNotSeeThisUnauthenticated' => null, |
|
142 | - ], |
|
143 | - 'extensions' => [ |
|
144 | - 'warnings' => [ |
|
145 | - [ |
|
146 | - 'message' => 'Access denied to this field.', |
|
147 | - 'locations' => [ |
|
148 | - [ |
|
149 | - 'line' => 2, |
|
150 | - 'column' => 3, |
|
151 | - ], |
|
152 | - ], |
|
153 | - 'path' => ['youShallNotSeeThisUnauthenticated'], |
|
154 | - ], |
|
155 | - ], |
|
156 | - ], |
|
157 | - ]; |
|
158 | - |
|
159 | - $query = <<<'QUERY' |
|
160 | - { |
|
161 | - youShallNotSeeThisUnauthenticated { |
|
162 | - secretValue |
|
163 | - youAreAuthenticated |
|
164 | - } |
|
165 | - } |
|
166 | - QUERY; |
|
167 | - |
|
168 | - $this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'access'); |
|
169 | - } |
|
170 | - |
|
171 | - public function testFullyAuthenticatedUserAccessToUserName(): void |
|
172 | - { |
|
173 | - $expected = [ |
|
174 | - 'data' => [ |
|
175 | - 'user' => [ |
|
176 | - 'name' => 'Dan', |
|
177 | - ], |
|
178 | - ], |
|
179 | - ]; |
|
180 | - |
|
181 | - $this->assertResponse($this->userNameQuery, $expected, static::USER_RYAN, 'access'); |
|
182 | - } |
|
183 | - |
|
184 | - public function testNotAuthenticatedUserAccessToUserRoles(): void |
|
185 | - { |
|
186 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::ANONYMOUS_USER, 'access'); |
|
187 | - } |
|
188 | - |
|
189 | - public function testAuthenticatedUserAccessToUserRolesWithoutEnoughRights(): void |
|
190 | - { |
|
191 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::USER_RYAN, 'access'); |
|
192 | - } |
|
193 | - |
|
194 | - public function testUserWithCorrectRightsAccessToUserRoles(): void |
|
195 | - { |
|
196 | - $expected = [ |
|
197 | - 'data' => [ |
|
198 | - 'user' => [ |
|
199 | - 'roles' => ['ROLE_USER'], |
|
200 | - ], |
|
201 | - ], |
|
202 | - ]; |
|
203 | - |
|
204 | - $this->assertResponse($this->userRolesQuery, $expected, static::USER_ADMIN, 'access'); |
|
205 | - } |
|
206 | - |
|
207 | - public function testUserForbiddenField(): void |
|
208 | - { |
|
209 | - $expected = [ |
|
210 | - 'data' => [ |
|
211 | - 'user' => null, |
|
212 | - ], |
|
213 | - 'extensions' => [ |
|
214 | - 'warnings' => [ |
|
215 | - [ |
|
216 | - 'message' => 'Access denied to this field.', |
|
217 | - 'locations' => [ |
|
218 | - [ |
|
219 | - 'line' => 3, |
|
220 | - 'column' => 5, |
|
221 | - ], |
|
222 | - ], |
|
223 | - 'path' => ['user', 'forbidden'], |
|
224 | - ], |
|
225 | - ], |
|
226 | - ], |
|
227 | - ]; |
|
228 | - |
|
229 | - $query = <<<'QUERY' |
|
230 | - query MyQuery { |
|
231 | - user { |
|
232 | - forbidden |
|
233 | - } |
|
234 | - } |
|
235 | - QUERY; |
|
236 | - |
|
237 | - $this->assertResponse($query, $expected, static::USER_ADMIN, 'access'); |
|
238 | - } |
|
239 | - |
|
240 | - public function testUserAccessToUserFriends(): void |
|
241 | - { |
|
242 | - $expected = [ |
|
243 | - 'data' => [ |
|
244 | - 'user' => [ |
|
245 | - 'friends' => [ |
|
246 | - 'edges' => [ |
|
247 | - ['node' => ['name' => 'Nick']], |
|
248 | - ['node' => null], |
|
249 | - ], |
|
250 | - ], |
|
251 | - ], |
|
252 | - ], |
|
253 | - ]; |
|
254 | - |
|
255 | - $this->assertResponse($this->userFriendsQuery, $expected, static::USER_ADMIN, 'access'); |
|
256 | - } |
|
257 | - |
|
258 | - public function testUserAccessToUserFriendsAsArray(): void |
|
259 | - { |
|
260 | - $expected = [ |
|
261 | - 'data' => [ |
|
262 | - 'user' => [ |
|
263 | - 'friendsAsArray' => [1, null, 3], |
|
264 | - ], |
|
265 | - ], |
|
266 | - ]; |
|
267 | - |
|
268 | - $this->assertResponse('query { user { friendsAsArray } }', $expected, static::USER_ADMIN, 'access'); |
|
269 | - } |
|
270 | - |
|
271 | - public function testMutationAllowedUser(): void |
|
272 | - { |
|
273 | - $result = 123; |
|
274 | - |
|
275 | - $expected = [ |
|
276 | - 'data' => [ |
|
277 | - 'simpleMutationWithThunkFields' => [ |
|
278 | - 'result' => $result, |
|
279 | - 'clientMutationId' => 'bac', |
|
280 | - ], |
|
281 | - ], |
|
282 | - ]; |
|
283 | - |
|
284 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, $result), $expected, static::USER_ADMIN, 'access'); |
|
285 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
286 | - } |
|
287 | - |
|
288 | - public function testMutationAllowedButNoRightsToDisplayPayload(): void |
|
289 | - { |
|
290 | - $expected = [ |
|
291 | - 'data' => [ |
|
292 | - 'simpleMutationWithThunkFields' => [ |
|
293 | - 'result' => null, |
|
294 | - 'clientMutationId' => 'bac', |
|
295 | - ], |
|
296 | - ], |
|
297 | - 'extensions' => [ |
|
298 | - 'warnings' => [ |
|
299 | - [ |
|
300 | - 'message' => 'Access denied to this field.', |
|
301 | - 'locations' => [ |
|
302 | - [ |
|
303 | - 'line' => 3, |
|
304 | - 'column' => 5, |
|
305 | - ], |
|
306 | - ], |
|
307 | - 'path' => ['simpleMutationWithThunkFields', 'result'], |
|
308 | - ], |
|
309 | - ], |
|
310 | - ], |
|
311 | - ]; |
|
312 | - |
|
313 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 321), $expected, static::USER_ADMIN, 'access'); |
|
314 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
315 | - } |
|
316 | - |
|
317 | - public function testMutationNotAllowedUser(): void |
|
318 | - { |
|
319 | - $expected = [ |
|
320 | - 'errors' => [ |
|
321 | - [ |
|
322 | - 'message' => 'Access denied to this field.', |
|
323 | - 'locations' => [ |
|
324 | - [ |
|
325 | - 'line' => 2, |
|
326 | - 'column' => 3, |
|
327 | - ], |
|
328 | - ], |
|
329 | - 'path' => ['simpleMutationWithThunkFields'], |
|
330 | - ], |
|
331 | - ], |
|
332 | - 'data' => [ |
|
333 | - 'simpleMutationWithThunkFields' => null, |
|
334 | - ], |
|
335 | - ]; |
|
336 | - |
|
337 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 123), $expected, static::USER_RYAN, 'access'); |
|
338 | - $this->assertFalse(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
339 | - } |
|
340 | - |
|
341 | - private function expectedFailedUserRoles(): array |
|
342 | - { |
|
343 | - return [ |
|
344 | - 'data' => [ |
|
345 | - 'user' => [ |
|
346 | - 'roles' => null, |
|
347 | - ], |
|
348 | - ], |
|
349 | - 'extensions' => [ |
|
350 | - 'warnings' => [ |
|
351 | - [ |
|
352 | - 'message' => 'Access denied to this field.', |
|
353 | - 'locations' => [ |
|
354 | - [ |
|
355 | - 'line' => 1, |
|
356 | - 'column' => 16, |
|
357 | - ], |
|
358 | - ], |
|
359 | - 'path' => [ |
|
360 | - 'user', |
|
361 | - 'roles', |
|
362 | - ], |
|
363 | - ], |
|
364 | - ], |
|
365 | - ], |
|
366 | - ]; |
|
367 | - } |
|
368 | -} |
@@ -26,343 +26,3 @@ |
||
26 | 26 | private string $userIsEnabledQuery = 'query ($hasAccess: Boolean = true) { user { isEnabled(hasAccess: $hasAccess) } }'; |
27 | 27 | |
28 | 28 | private string $userFriendsQuery = <<<'QUERY' |
29 | - query { |
|
30 | - user { |
|
31 | - friends(first: 2) { |
|
32 | - edges { |
|
33 | - node { |
|
34 | - name |
|
35 | - } |
|
36 | - } |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - QUERY; |
|
41 | - |
|
42 | - private string $simpleMutationWithThunkQuery = <<<'MUTATION' |
|
43 | - mutation M { |
|
44 | - simpleMutationWithThunkFields(input: {inputData: %d, clientMutationId: "bac"}) { |
|
45 | - result |
|
46 | - clientMutationId |
|
47 | - } |
|
48 | - } |
|
49 | - MUTATION; |
|
50 | - |
|
51 | - public function setUp(): void |
|
52 | - { |
|
53 | - parent::setUp(); |
|
54 | - // load types |
|
55 | - $this->loader = function ($class): void { |
|
56 | - if (preg_match('@^'.preg_quote('Overblog\GraphQLBundle\Access\__DEFINITIONS__\\').'(.*)$@', $class, $matches)) { |
|
57 | - $file = sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/access/cache/testaccess/overblog/graphql-bundle/__definitions__/'.$matches[1].'.php'; |
|
58 | - if (file_exists($file)) { |
|
59 | - require $file; |
|
60 | - } |
|
61 | - } |
|
62 | - }; |
|
63 | - spl_autoload_register($this->loader); |
|
64 | - } |
|
65 | - |
|
66 | - public function testCustomClassLoaderNotRegister(): void |
|
67 | - { |
|
68 | - $this->expectException(Error::class); |
|
69 | - if ((int) phpversion() <= 7) { |
|
70 | - $this->expectExceptionMessage('Class \'Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType\' not found'); |
|
71 | - } else { |
|
72 | - $this->expectExceptionMessage('Class "Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType" not found'); |
|
73 | - } |
|
74 | - spl_autoload_unregister($this->loader); |
|
75 | - $this->assertResponse($this->userNameQuery, [], static::ANONYMOUS_USER, 'access'); |
|
76 | - } |
|
77 | - |
|
78 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledTrue(): void |
|
79 | - { |
|
80 | - $this->assertResponse( |
|
81 | - $this->userIsEnabledQuery, |
|
82 | - ['data' => ['user' => ['isEnabled' => true]]], |
|
83 | - static::ANONYMOUS_USER, |
|
84 | - 'access' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledFalse(): void |
|
89 | - { |
|
90 | - $this->assertResponse( |
|
91 | - $this->userIsEnabledQuery, |
|
92 | - [ |
|
93 | - 'data' => [ |
|
94 | - 'user' => [ |
|
95 | - 'isEnabled' => null, |
|
96 | - ], |
|
97 | - ], |
|
98 | - 'extensions' => [ |
|
99 | - 'warnings' => [ |
|
100 | - [ |
|
101 | - 'message' => 'Access denied to this field.', |
|
102 | - 'locations' => [['line' => 1, 'column' => 45]], |
|
103 | - 'path' => ['user', 'isEnabled'], |
|
104 | - ], |
|
105 | - ], |
|
106 | - ], |
|
107 | - ], |
|
108 | - static::ANONYMOUS_USER, |
|
109 | - 'access', |
|
110 | - '', |
|
111 | - ['hasAccess' => false] |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - public function testNotAuthenticatedUserAccessToUserName(): void |
|
116 | - { |
|
117 | - $expected = [ |
|
118 | - 'data' => [ |
|
119 | - 'user' => [ |
|
120 | - 'name' => null, |
|
121 | - ], |
|
122 | - ], |
|
123 | - 'extensions' => [ |
|
124 | - 'warnings' => [ |
|
125 | - [ |
|
126 | - 'message' => 'Access denied to this field.', |
|
127 | - 'locations' => [['line' => 1, 'column' => 16]], |
|
128 | - 'path' => ['user', 'name'], |
|
129 | - ], |
|
130 | - ], |
|
131 | - ], |
|
132 | - ]; |
|
133 | - |
|
134 | - $this->assertResponse($this->userNameQuery, $expected, static::ANONYMOUS_USER, 'access'); |
|
135 | - } |
|
136 | - |
|
137 | - public function testNonAuthenticatedUserAccessSecuredFieldWhichInitiallyResolvesToArray(): void |
|
138 | - { |
|
139 | - $expected = [ |
|
140 | - 'data' => [ |
|
141 | - 'youShallNotSeeThisUnauthenticated' => null, |
|
142 | - ], |
|
143 | - 'extensions' => [ |
|
144 | - 'warnings' => [ |
|
145 | - [ |
|
146 | - 'message' => 'Access denied to this field.', |
|
147 | - 'locations' => [ |
|
148 | - [ |
|
149 | - 'line' => 2, |
|
150 | - 'column' => 3, |
|
151 | - ], |
|
152 | - ], |
|
153 | - 'path' => ['youShallNotSeeThisUnauthenticated'], |
|
154 | - ], |
|
155 | - ], |
|
156 | - ], |
|
157 | - ]; |
|
158 | - |
|
159 | - $query = <<<'QUERY' |
|
160 | - { |
|
161 | - youShallNotSeeThisUnauthenticated { |
|
162 | - secretValue |
|
163 | - youAreAuthenticated |
|
164 | - } |
|
165 | - } |
|
166 | - QUERY; |
|
167 | - |
|
168 | - $this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'access'); |
|
169 | - } |
|
170 | - |
|
171 | - public function testFullyAuthenticatedUserAccessToUserName(): void |
|
172 | - { |
|
173 | - $expected = [ |
|
174 | - 'data' => [ |
|
175 | - 'user' => [ |
|
176 | - 'name' => 'Dan', |
|
177 | - ], |
|
178 | - ], |
|
179 | - ]; |
|
180 | - |
|
181 | - $this->assertResponse($this->userNameQuery, $expected, static::USER_RYAN, 'access'); |
|
182 | - } |
|
183 | - |
|
184 | - public function testNotAuthenticatedUserAccessToUserRoles(): void |
|
185 | - { |
|
186 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::ANONYMOUS_USER, 'access'); |
|
187 | - } |
|
188 | - |
|
189 | - public function testAuthenticatedUserAccessToUserRolesWithoutEnoughRights(): void |
|
190 | - { |
|
191 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::USER_RYAN, 'access'); |
|
192 | - } |
|
193 | - |
|
194 | - public function testUserWithCorrectRightsAccessToUserRoles(): void |
|
195 | - { |
|
196 | - $expected = [ |
|
197 | - 'data' => [ |
|
198 | - 'user' => [ |
|
199 | - 'roles' => ['ROLE_USER'], |
|
200 | - ], |
|
201 | - ], |
|
202 | - ]; |
|
203 | - |
|
204 | - $this->assertResponse($this->userRolesQuery, $expected, static::USER_ADMIN, 'access'); |
|
205 | - } |
|
206 | - |
|
207 | - public function testUserForbiddenField(): void |
|
208 | - { |
|
209 | - $expected = [ |
|
210 | - 'data' => [ |
|
211 | - 'user' => null, |
|
212 | - ], |
|
213 | - 'extensions' => [ |
|
214 | - 'warnings' => [ |
|
215 | - [ |
|
216 | - 'message' => 'Access denied to this field.', |
|
217 | - 'locations' => [ |
|
218 | - [ |
|
219 | - 'line' => 3, |
|
220 | - 'column' => 5, |
|
221 | - ], |
|
222 | - ], |
|
223 | - 'path' => ['user', 'forbidden'], |
|
224 | - ], |
|
225 | - ], |
|
226 | - ], |
|
227 | - ]; |
|
228 | - |
|
229 | - $query = <<<'QUERY' |
|
230 | - query MyQuery { |
|
231 | - user { |
|
232 | - forbidden |
|
233 | - } |
|
234 | - } |
|
235 | - QUERY; |
|
236 | - |
|
237 | - $this->assertResponse($query, $expected, static::USER_ADMIN, 'access'); |
|
238 | - } |
|
239 | - |
|
240 | - public function testUserAccessToUserFriends(): void |
|
241 | - { |
|
242 | - $expected = [ |
|
243 | - 'data' => [ |
|
244 | - 'user' => [ |
|
245 | - 'friends' => [ |
|
246 | - 'edges' => [ |
|
247 | - ['node' => ['name' => 'Nick']], |
|
248 | - ['node' => null], |
|
249 | - ], |
|
250 | - ], |
|
251 | - ], |
|
252 | - ], |
|
253 | - ]; |
|
254 | - |
|
255 | - $this->assertResponse($this->userFriendsQuery, $expected, static::USER_ADMIN, 'access'); |
|
256 | - } |
|
257 | - |
|
258 | - public function testUserAccessToUserFriendsAsArray(): void |
|
259 | - { |
|
260 | - $expected = [ |
|
261 | - 'data' => [ |
|
262 | - 'user' => [ |
|
263 | - 'friendsAsArray' => [1, null, 3], |
|
264 | - ], |
|
265 | - ], |
|
266 | - ]; |
|
267 | - |
|
268 | - $this->assertResponse('query { user { friendsAsArray } }', $expected, static::USER_ADMIN, 'access'); |
|
269 | - } |
|
270 | - |
|
271 | - public function testMutationAllowedUser(): void |
|
272 | - { |
|
273 | - $result = 123; |
|
274 | - |
|
275 | - $expected = [ |
|
276 | - 'data' => [ |
|
277 | - 'simpleMutationWithThunkFields' => [ |
|
278 | - 'result' => $result, |
|
279 | - 'clientMutationId' => 'bac', |
|
280 | - ], |
|
281 | - ], |
|
282 | - ]; |
|
283 | - |
|
284 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, $result), $expected, static::USER_ADMIN, 'access'); |
|
285 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
286 | - } |
|
287 | - |
|
288 | - public function testMutationAllowedButNoRightsToDisplayPayload(): void |
|
289 | - { |
|
290 | - $expected = [ |
|
291 | - 'data' => [ |
|
292 | - 'simpleMutationWithThunkFields' => [ |
|
293 | - 'result' => null, |
|
294 | - 'clientMutationId' => 'bac', |
|
295 | - ], |
|
296 | - ], |
|
297 | - 'extensions' => [ |
|
298 | - 'warnings' => [ |
|
299 | - [ |
|
300 | - 'message' => 'Access denied to this field.', |
|
301 | - 'locations' => [ |
|
302 | - [ |
|
303 | - 'line' => 3, |
|
304 | - 'column' => 5, |
|
305 | - ], |
|
306 | - ], |
|
307 | - 'path' => ['simpleMutationWithThunkFields', 'result'], |
|
308 | - ], |
|
309 | - ], |
|
310 | - ], |
|
311 | - ]; |
|
312 | - |
|
313 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 321), $expected, static::USER_ADMIN, 'access'); |
|
314 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
315 | - } |
|
316 | - |
|
317 | - public function testMutationNotAllowedUser(): void |
|
318 | - { |
|
319 | - $expected = [ |
|
320 | - 'errors' => [ |
|
321 | - [ |
|
322 | - 'message' => 'Access denied to this field.', |
|
323 | - 'locations' => [ |
|
324 | - [ |
|
325 | - 'line' => 2, |
|
326 | - 'column' => 3, |
|
327 | - ], |
|
328 | - ], |
|
329 | - 'path' => ['simpleMutationWithThunkFields'], |
|
330 | - ], |
|
331 | - ], |
|
332 | - 'data' => [ |
|
333 | - 'simpleMutationWithThunkFields' => null, |
|
334 | - ], |
|
335 | - ]; |
|
336 | - |
|
337 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 123), $expected, static::USER_RYAN, 'access'); |
|
338 | - $this->assertFalse(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
339 | - } |
|
340 | - |
|
341 | - private function expectedFailedUserRoles(): array |
|
342 | - { |
|
343 | - return [ |
|
344 | - 'data' => [ |
|
345 | - 'user' => [ |
|
346 | - 'roles' => null, |
|
347 | - ], |
|
348 | - ], |
|
349 | - 'extensions' => [ |
|
350 | - 'warnings' => [ |
|
351 | - [ |
|
352 | - 'message' => 'Access denied to this field.', |
|
353 | - 'locations' => [ |
|
354 | - [ |
|
355 | - 'line' => 1, |
|
356 | - 'column' => 16, |
|
357 | - ], |
|
358 | - ], |
|
359 | - 'path' => [ |
|
360 | - 'user', |
|
361 | - 'roles', |
|
362 | - ], |
|
363 | - ], |
|
364 | - ], |
|
365 | - ], |
|
366 | - ]; |
|
367 | - } |
|
368 | -} |
@@ -26,343 +26,3 @@ |
||
26 | 26 | private string $userIsEnabledQuery = 'query ($hasAccess: Boolean = true) { user { isEnabled(hasAccess: $hasAccess) } }'; |
27 | 27 | |
28 | 28 | private string $userFriendsQuery = <<<'QUERY' |
29 | - query { |
|
30 | - user { |
|
31 | - friends(first: 2) { |
|
32 | - edges { |
|
33 | - node { |
|
34 | - name |
|
35 | - } |
|
36 | - } |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - QUERY; |
|
41 | - |
|
42 | - private string $simpleMutationWithThunkQuery = <<<'MUTATION' |
|
43 | - mutation M { |
|
44 | - simpleMutationWithThunkFields(input: {inputData: %d, clientMutationId: "bac"}) { |
|
45 | - result |
|
46 | - clientMutationId |
|
47 | - } |
|
48 | - } |
|
49 | - MUTATION; |
|
50 | - |
|
51 | - public function setUp(): void |
|
52 | - { |
|
53 | - parent::setUp(); |
|
54 | - // load types |
|
55 | - $this->loader = function ($class): void { |
|
56 | - if (preg_match('@^'.preg_quote('Overblog\GraphQLBundle\Access\__DEFINITIONS__\\').'(.*)$@', $class, $matches)) { |
|
57 | - $file = sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/access/cache/testaccess/overblog/graphql-bundle/__definitions__/'.$matches[1].'.php'; |
|
58 | - if (file_exists($file)) { |
|
59 | - require $file; |
|
60 | - } |
|
61 | - } |
|
62 | - }; |
|
63 | - spl_autoload_register($this->loader); |
|
64 | - } |
|
65 | - |
|
66 | - public function testCustomClassLoaderNotRegister(): void |
|
67 | - { |
|
68 | - $this->expectException(Error::class); |
|
69 | - if ((int) phpversion() <= 7) { |
|
70 | - $this->expectExceptionMessage('Class \'Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType\' not found'); |
|
71 | - } else { |
|
72 | - $this->expectExceptionMessage('Class "Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType" not found'); |
|
73 | - } |
|
74 | - spl_autoload_unregister($this->loader); |
|
75 | - $this->assertResponse($this->userNameQuery, [], static::ANONYMOUS_USER, 'access'); |
|
76 | - } |
|
77 | - |
|
78 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledTrue(): void |
|
79 | - { |
|
80 | - $this->assertResponse( |
|
81 | - $this->userIsEnabledQuery, |
|
82 | - ['data' => ['user' => ['isEnabled' => true]]], |
|
83 | - static::ANONYMOUS_USER, |
|
84 | - 'access' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledFalse(): void |
|
89 | - { |
|
90 | - $this->assertResponse( |
|
91 | - $this->userIsEnabledQuery, |
|
92 | - [ |
|
93 | - 'data' => [ |
|
94 | - 'user' => [ |
|
95 | - 'isEnabled' => null, |
|
96 | - ], |
|
97 | - ], |
|
98 | - 'extensions' => [ |
|
99 | - 'warnings' => [ |
|
100 | - [ |
|
101 | - 'message' => 'Access denied to this field.', |
|
102 | - 'locations' => [['line' => 1, 'column' => 45]], |
|
103 | - 'path' => ['user', 'isEnabled'], |
|
104 | - ], |
|
105 | - ], |
|
106 | - ], |
|
107 | - ], |
|
108 | - static::ANONYMOUS_USER, |
|
109 | - 'access', |
|
110 | - '', |
|
111 | - ['hasAccess' => false] |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - public function testNotAuthenticatedUserAccessToUserName(): void |
|
116 | - { |
|
117 | - $expected = [ |
|
118 | - 'data' => [ |
|
119 | - 'user' => [ |
|
120 | - 'name' => null, |
|
121 | - ], |
|
122 | - ], |
|
123 | - 'extensions' => [ |
|
124 | - 'warnings' => [ |
|
125 | - [ |
|
126 | - 'message' => 'Access denied to this field.', |
|
127 | - 'locations' => [['line' => 1, 'column' => 16]], |
|
128 | - 'path' => ['user', 'name'], |
|
129 | - ], |
|
130 | - ], |
|
131 | - ], |
|
132 | - ]; |
|
133 | - |
|
134 | - $this->assertResponse($this->userNameQuery, $expected, static::ANONYMOUS_USER, 'access'); |
|
135 | - } |
|
136 | - |
|
137 | - public function testNonAuthenticatedUserAccessSecuredFieldWhichInitiallyResolvesToArray(): void |
|
138 | - { |
|
139 | - $expected = [ |
|
140 | - 'data' => [ |
|
141 | - 'youShallNotSeeThisUnauthenticated' => null, |
|
142 | - ], |
|
143 | - 'extensions' => [ |
|
144 | - 'warnings' => [ |
|
145 | - [ |
|
146 | - 'message' => 'Access denied to this field.', |
|
147 | - 'locations' => [ |
|
148 | - [ |
|
149 | - 'line' => 2, |
|
150 | - 'column' => 3, |
|
151 | - ], |
|
152 | - ], |
|
153 | - 'path' => ['youShallNotSeeThisUnauthenticated'], |
|
154 | - ], |
|
155 | - ], |
|
156 | - ], |
|
157 | - ]; |
|
158 | - |
|
159 | - $query = <<<'QUERY' |
|
160 | - { |
|
161 | - youShallNotSeeThisUnauthenticated { |
|
162 | - secretValue |
|
163 | - youAreAuthenticated |
|
164 | - } |
|
165 | - } |
|
166 | - QUERY; |
|
167 | - |
|
168 | - $this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'access'); |
|
169 | - } |
|
170 | - |
|
171 | - public function testFullyAuthenticatedUserAccessToUserName(): void |
|
172 | - { |
|
173 | - $expected = [ |
|
174 | - 'data' => [ |
|
175 | - 'user' => [ |
|
176 | - 'name' => 'Dan', |
|
177 | - ], |
|
178 | - ], |
|
179 | - ]; |
|
180 | - |
|
181 | - $this->assertResponse($this->userNameQuery, $expected, static::USER_RYAN, 'access'); |
|
182 | - } |
|
183 | - |
|
184 | - public function testNotAuthenticatedUserAccessToUserRoles(): void |
|
185 | - { |
|
186 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::ANONYMOUS_USER, 'access'); |
|
187 | - } |
|
188 | - |
|
189 | - public function testAuthenticatedUserAccessToUserRolesWithoutEnoughRights(): void |
|
190 | - { |
|
191 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::USER_RYAN, 'access'); |
|
192 | - } |
|
193 | - |
|
194 | - public function testUserWithCorrectRightsAccessToUserRoles(): void |
|
195 | - { |
|
196 | - $expected = [ |
|
197 | - 'data' => [ |
|
198 | - 'user' => [ |
|
199 | - 'roles' => ['ROLE_USER'], |
|
200 | - ], |
|
201 | - ], |
|
202 | - ]; |
|
203 | - |
|
204 | - $this->assertResponse($this->userRolesQuery, $expected, static::USER_ADMIN, 'access'); |
|
205 | - } |
|
206 | - |
|
207 | - public function testUserForbiddenField(): void |
|
208 | - { |
|
209 | - $expected = [ |
|
210 | - 'data' => [ |
|
211 | - 'user' => null, |
|
212 | - ], |
|
213 | - 'extensions' => [ |
|
214 | - 'warnings' => [ |
|
215 | - [ |
|
216 | - 'message' => 'Access denied to this field.', |
|
217 | - 'locations' => [ |
|
218 | - [ |
|
219 | - 'line' => 3, |
|
220 | - 'column' => 5, |
|
221 | - ], |
|
222 | - ], |
|
223 | - 'path' => ['user', 'forbidden'], |
|
224 | - ], |
|
225 | - ], |
|
226 | - ], |
|
227 | - ]; |
|
228 | - |
|
229 | - $query = <<<'QUERY' |
|
230 | - query MyQuery { |
|
231 | - user { |
|
232 | - forbidden |
|
233 | - } |
|
234 | - } |
|
235 | - QUERY; |
|
236 | - |
|
237 | - $this->assertResponse($query, $expected, static::USER_ADMIN, 'access'); |
|
238 | - } |
|
239 | - |
|
240 | - public function testUserAccessToUserFriends(): void |
|
241 | - { |
|
242 | - $expected = [ |
|
243 | - 'data' => [ |
|
244 | - 'user' => [ |
|
245 | - 'friends' => [ |
|
246 | - 'edges' => [ |
|
247 | - ['node' => ['name' => 'Nick']], |
|
248 | - ['node' => null], |
|
249 | - ], |
|
250 | - ], |
|
251 | - ], |
|
252 | - ], |
|
253 | - ]; |
|
254 | - |
|
255 | - $this->assertResponse($this->userFriendsQuery, $expected, static::USER_ADMIN, 'access'); |
|
256 | - } |
|
257 | - |
|
258 | - public function testUserAccessToUserFriendsAsArray(): void |
|
259 | - { |
|
260 | - $expected = [ |
|
261 | - 'data' => [ |
|
262 | - 'user' => [ |
|
263 | - 'friendsAsArray' => [1, null, 3], |
|
264 | - ], |
|
265 | - ], |
|
266 | - ]; |
|
267 | - |
|
268 | - $this->assertResponse('query { user { friendsAsArray } }', $expected, static::USER_ADMIN, 'access'); |
|
269 | - } |
|
270 | - |
|
271 | - public function testMutationAllowedUser(): void |
|
272 | - { |
|
273 | - $result = 123; |
|
274 | - |
|
275 | - $expected = [ |
|
276 | - 'data' => [ |
|
277 | - 'simpleMutationWithThunkFields' => [ |
|
278 | - 'result' => $result, |
|
279 | - 'clientMutationId' => 'bac', |
|
280 | - ], |
|
281 | - ], |
|
282 | - ]; |
|
283 | - |
|
284 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, $result), $expected, static::USER_ADMIN, 'access'); |
|
285 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
286 | - } |
|
287 | - |
|
288 | - public function testMutationAllowedButNoRightsToDisplayPayload(): void |
|
289 | - { |
|
290 | - $expected = [ |
|
291 | - 'data' => [ |
|
292 | - 'simpleMutationWithThunkFields' => [ |
|
293 | - 'result' => null, |
|
294 | - 'clientMutationId' => 'bac', |
|
295 | - ], |
|
296 | - ], |
|
297 | - 'extensions' => [ |
|
298 | - 'warnings' => [ |
|
299 | - [ |
|
300 | - 'message' => 'Access denied to this field.', |
|
301 | - 'locations' => [ |
|
302 | - [ |
|
303 | - 'line' => 3, |
|
304 | - 'column' => 5, |
|
305 | - ], |
|
306 | - ], |
|
307 | - 'path' => ['simpleMutationWithThunkFields', 'result'], |
|
308 | - ], |
|
309 | - ], |
|
310 | - ], |
|
311 | - ]; |
|
312 | - |
|
313 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 321), $expected, static::USER_ADMIN, 'access'); |
|
314 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
315 | - } |
|
316 | - |
|
317 | - public function testMutationNotAllowedUser(): void |
|
318 | - { |
|
319 | - $expected = [ |
|
320 | - 'errors' => [ |
|
321 | - [ |
|
322 | - 'message' => 'Access denied to this field.', |
|
323 | - 'locations' => [ |
|
324 | - [ |
|
325 | - 'line' => 2, |
|
326 | - 'column' => 3, |
|
327 | - ], |
|
328 | - ], |
|
329 | - 'path' => ['simpleMutationWithThunkFields'], |
|
330 | - ], |
|
331 | - ], |
|
332 | - 'data' => [ |
|
333 | - 'simpleMutationWithThunkFields' => null, |
|
334 | - ], |
|
335 | - ]; |
|
336 | - |
|
337 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 123), $expected, static::USER_RYAN, 'access'); |
|
338 | - $this->assertFalse(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
339 | - } |
|
340 | - |
|
341 | - private function expectedFailedUserRoles(): array |
|
342 | - { |
|
343 | - return [ |
|
344 | - 'data' => [ |
|
345 | - 'user' => [ |
|
346 | - 'roles' => null, |
|
347 | - ], |
|
348 | - ], |
|
349 | - 'extensions' => [ |
|
350 | - 'warnings' => [ |
|
351 | - [ |
|
352 | - 'message' => 'Access denied to this field.', |
|
353 | - 'locations' => [ |
|
354 | - [ |
|
355 | - 'line' => 1, |
|
356 | - 'column' => 16, |
|
357 | - ], |
|
358 | - ], |
|
359 | - 'path' => [ |
|
360 | - 'user', |
|
361 | - 'roles', |
|
362 | - ], |
|
363 | - ], |
|
364 | - ], |
|
365 | - ], |
|
366 | - ]; |
|
367 | - } |
|
368 | -} |
@@ -26,343 +26,3 @@ |
||
26 | 26 | private string $userIsEnabledQuery = 'query ($hasAccess: Boolean = true) { user { isEnabled(hasAccess: $hasAccess) } }'; |
27 | 27 | |
28 | 28 | private string $userFriendsQuery = <<<'QUERY' |
29 | - query { |
|
30 | - user { |
|
31 | - friends(first: 2) { |
|
32 | - edges { |
|
33 | - node { |
|
34 | - name |
|
35 | - } |
|
36 | - } |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - QUERY; |
|
41 | - |
|
42 | - private string $simpleMutationWithThunkQuery = <<<'MUTATION' |
|
43 | - mutation M { |
|
44 | - simpleMutationWithThunkFields(input: {inputData: %d, clientMutationId: "bac"}) { |
|
45 | - result |
|
46 | - clientMutationId |
|
47 | - } |
|
48 | - } |
|
49 | - MUTATION; |
|
50 | - |
|
51 | - public function setUp(): void |
|
52 | - { |
|
53 | - parent::setUp(); |
|
54 | - // load types |
|
55 | - $this->loader = function ($class): void { |
|
56 | - if (preg_match('@^'.preg_quote('Overblog\GraphQLBundle\Access\__DEFINITIONS__\\').'(.*)$@', $class, $matches)) { |
|
57 | - $file = sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/access/cache/testaccess/overblog/graphql-bundle/__definitions__/'.$matches[1].'.php'; |
|
58 | - if (file_exists($file)) { |
|
59 | - require $file; |
|
60 | - } |
|
61 | - } |
|
62 | - }; |
|
63 | - spl_autoload_register($this->loader); |
|
64 | - } |
|
65 | - |
|
66 | - public function testCustomClassLoaderNotRegister(): void |
|
67 | - { |
|
68 | - $this->expectException(Error::class); |
|
69 | - if ((int) phpversion() <= 7) { |
|
70 | - $this->expectExceptionMessage('Class \'Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType\' not found'); |
|
71 | - } else { |
|
72 | - $this->expectExceptionMessage('Class "Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType" not found'); |
|
73 | - } |
|
74 | - spl_autoload_unregister($this->loader); |
|
75 | - $this->assertResponse($this->userNameQuery, [], static::ANONYMOUS_USER, 'access'); |
|
76 | - } |
|
77 | - |
|
78 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledTrue(): void |
|
79 | - { |
|
80 | - $this->assertResponse( |
|
81 | - $this->userIsEnabledQuery, |
|
82 | - ['data' => ['user' => ['isEnabled' => true]]], |
|
83 | - static::ANONYMOUS_USER, |
|
84 | - 'access' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledFalse(): void |
|
89 | - { |
|
90 | - $this->assertResponse( |
|
91 | - $this->userIsEnabledQuery, |
|
92 | - [ |
|
93 | - 'data' => [ |
|
94 | - 'user' => [ |
|
95 | - 'isEnabled' => null, |
|
96 | - ], |
|
97 | - ], |
|
98 | - 'extensions' => [ |
|
99 | - 'warnings' => [ |
|
100 | - [ |
|
101 | - 'message' => 'Access denied to this field.', |
|
102 | - 'locations' => [['line' => 1, 'column' => 45]], |
|
103 | - 'path' => ['user', 'isEnabled'], |
|
104 | - ], |
|
105 | - ], |
|
106 | - ], |
|
107 | - ], |
|
108 | - static::ANONYMOUS_USER, |
|
109 | - 'access', |
|
110 | - '', |
|
111 | - ['hasAccess' => false] |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - public function testNotAuthenticatedUserAccessToUserName(): void |
|
116 | - { |
|
117 | - $expected = [ |
|
118 | - 'data' => [ |
|
119 | - 'user' => [ |
|
120 | - 'name' => null, |
|
121 | - ], |
|
122 | - ], |
|
123 | - 'extensions' => [ |
|
124 | - 'warnings' => [ |
|
125 | - [ |
|
126 | - 'message' => 'Access denied to this field.', |
|
127 | - 'locations' => [['line' => 1, 'column' => 16]], |
|
128 | - 'path' => ['user', 'name'], |
|
129 | - ], |
|
130 | - ], |
|
131 | - ], |
|
132 | - ]; |
|
133 | - |
|
134 | - $this->assertResponse($this->userNameQuery, $expected, static::ANONYMOUS_USER, 'access'); |
|
135 | - } |
|
136 | - |
|
137 | - public function testNonAuthenticatedUserAccessSecuredFieldWhichInitiallyResolvesToArray(): void |
|
138 | - { |
|
139 | - $expected = [ |
|
140 | - 'data' => [ |
|
141 | - 'youShallNotSeeThisUnauthenticated' => null, |
|
142 | - ], |
|
143 | - 'extensions' => [ |
|
144 | - 'warnings' => [ |
|
145 | - [ |
|
146 | - 'message' => 'Access denied to this field.', |
|
147 | - 'locations' => [ |
|
148 | - [ |
|
149 | - 'line' => 2, |
|
150 | - 'column' => 3, |
|
151 | - ], |
|
152 | - ], |
|
153 | - 'path' => ['youShallNotSeeThisUnauthenticated'], |
|
154 | - ], |
|
155 | - ], |
|
156 | - ], |
|
157 | - ]; |
|
158 | - |
|
159 | - $query = <<<'QUERY' |
|
160 | - { |
|
161 | - youShallNotSeeThisUnauthenticated { |
|
162 | - secretValue |
|
163 | - youAreAuthenticated |
|
164 | - } |
|
165 | - } |
|
166 | - QUERY; |
|
167 | - |
|
168 | - $this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'access'); |
|
169 | - } |
|
170 | - |
|
171 | - public function testFullyAuthenticatedUserAccessToUserName(): void |
|
172 | - { |
|
173 | - $expected = [ |
|
174 | - 'data' => [ |
|
175 | - 'user' => [ |
|
176 | - 'name' => 'Dan', |
|
177 | - ], |
|
178 | - ], |
|
179 | - ]; |
|
180 | - |
|
181 | - $this->assertResponse($this->userNameQuery, $expected, static::USER_RYAN, 'access'); |
|
182 | - } |
|
183 | - |
|
184 | - public function testNotAuthenticatedUserAccessToUserRoles(): void |
|
185 | - { |
|
186 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::ANONYMOUS_USER, 'access'); |
|
187 | - } |
|
188 | - |
|
189 | - public function testAuthenticatedUserAccessToUserRolesWithoutEnoughRights(): void |
|
190 | - { |
|
191 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::USER_RYAN, 'access'); |
|
192 | - } |
|
193 | - |
|
194 | - public function testUserWithCorrectRightsAccessToUserRoles(): void |
|
195 | - { |
|
196 | - $expected = [ |
|
197 | - 'data' => [ |
|
198 | - 'user' => [ |
|
199 | - 'roles' => ['ROLE_USER'], |
|
200 | - ], |
|
201 | - ], |
|
202 | - ]; |
|
203 | - |
|
204 | - $this->assertResponse($this->userRolesQuery, $expected, static::USER_ADMIN, 'access'); |
|
205 | - } |
|
206 | - |
|
207 | - public function testUserForbiddenField(): void |
|
208 | - { |
|
209 | - $expected = [ |
|
210 | - 'data' => [ |
|
211 | - 'user' => null, |
|
212 | - ], |
|
213 | - 'extensions' => [ |
|
214 | - 'warnings' => [ |
|
215 | - [ |
|
216 | - 'message' => 'Access denied to this field.', |
|
217 | - 'locations' => [ |
|
218 | - [ |
|
219 | - 'line' => 3, |
|
220 | - 'column' => 5, |
|
221 | - ], |
|
222 | - ], |
|
223 | - 'path' => ['user', 'forbidden'], |
|
224 | - ], |
|
225 | - ], |
|
226 | - ], |
|
227 | - ]; |
|
228 | - |
|
229 | - $query = <<<'QUERY' |
|
230 | - query MyQuery { |
|
231 | - user { |
|
232 | - forbidden |
|
233 | - } |
|
234 | - } |
|
235 | - QUERY; |
|
236 | - |
|
237 | - $this->assertResponse($query, $expected, static::USER_ADMIN, 'access'); |
|
238 | - } |
|
239 | - |
|
240 | - public function testUserAccessToUserFriends(): void |
|
241 | - { |
|
242 | - $expected = [ |
|
243 | - 'data' => [ |
|
244 | - 'user' => [ |
|
245 | - 'friends' => [ |
|
246 | - 'edges' => [ |
|
247 | - ['node' => ['name' => 'Nick']], |
|
248 | - ['node' => null], |
|
249 | - ], |
|
250 | - ], |
|
251 | - ], |
|
252 | - ], |
|
253 | - ]; |
|
254 | - |
|
255 | - $this->assertResponse($this->userFriendsQuery, $expected, static::USER_ADMIN, 'access'); |
|
256 | - } |
|
257 | - |
|
258 | - public function testUserAccessToUserFriendsAsArray(): void |
|
259 | - { |
|
260 | - $expected = [ |
|
261 | - 'data' => [ |
|
262 | - 'user' => [ |
|
263 | - 'friendsAsArray' => [1, null, 3], |
|
264 | - ], |
|
265 | - ], |
|
266 | - ]; |
|
267 | - |
|
268 | - $this->assertResponse('query { user { friendsAsArray } }', $expected, static::USER_ADMIN, 'access'); |
|
269 | - } |
|
270 | - |
|
271 | - public function testMutationAllowedUser(): void |
|
272 | - { |
|
273 | - $result = 123; |
|
274 | - |
|
275 | - $expected = [ |
|
276 | - 'data' => [ |
|
277 | - 'simpleMutationWithThunkFields' => [ |
|
278 | - 'result' => $result, |
|
279 | - 'clientMutationId' => 'bac', |
|
280 | - ], |
|
281 | - ], |
|
282 | - ]; |
|
283 | - |
|
284 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, $result), $expected, static::USER_ADMIN, 'access'); |
|
285 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
286 | - } |
|
287 | - |
|
288 | - public function testMutationAllowedButNoRightsToDisplayPayload(): void |
|
289 | - { |
|
290 | - $expected = [ |
|
291 | - 'data' => [ |
|
292 | - 'simpleMutationWithThunkFields' => [ |
|
293 | - 'result' => null, |
|
294 | - 'clientMutationId' => 'bac', |
|
295 | - ], |
|
296 | - ], |
|
297 | - 'extensions' => [ |
|
298 | - 'warnings' => [ |
|
299 | - [ |
|
300 | - 'message' => 'Access denied to this field.', |
|
301 | - 'locations' => [ |
|
302 | - [ |
|
303 | - 'line' => 3, |
|
304 | - 'column' => 5, |
|
305 | - ], |
|
306 | - ], |
|
307 | - 'path' => ['simpleMutationWithThunkFields', 'result'], |
|
308 | - ], |
|
309 | - ], |
|
310 | - ], |
|
311 | - ]; |
|
312 | - |
|
313 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 321), $expected, static::USER_ADMIN, 'access'); |
|
314 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
315 | - } |
|
316 | - |
|
317 | - public function testMutationNotAllowedUser(): void |
|
318 | - { |
|
319 | - $expected = [ |
|
320 | - 'errors' => [ |
|
321 | - [ |
|
322 | - 'message' => 'Access denied to this field.', |
|
323 | - 'locations' => [ |
|
324 | - [ |
|
325 | - 'line' => 2, |
|
326 | - 'column' => 3, |
|
327 | - ], |
|
328 | - ], |
|
329 | - 'path' => ['simpleMutationWithThunkFields'], |
|
330 | - ], |
|
331 | - ], |
|
332 | - 'data' => [ |
|
333 | - 'simpleMutationWithThunkFields' => null, |
|
334 | - ], |
|
335 | - ]; |
|
336 | - |
|
337 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 123), $expected, static::USER_RYAN, 'access'); |
|
338 | - $this->assertFalse(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
339 | - } |
|
340 | - |
|
341 | - private function expectedFailedUserRoles(): array |
|
342 | - { |
|
343 | - return [ |
|
344 | - 'data' => [ |
|
345 | - 'user' => [ |
|
346 | - 'roles' => null, |
|
347 | - ], |
|
348 | - ], |
|
349 | - 'extensions' => [ |
|
350 | - 'warnings' => [ |
|
351 | - [ |
|
352 | - 'message' => 'Access denied to this field.', |
|
353 | - 'locations' => [ |
|
354 | - [ |
|
355 | - 'line' => 1, |
|
356 | - 'column' => 16, |
|
357 | - ], |
|
358 | - ], |
|
359 | - 'path' => [ |
|
360 | - 'user', |
|
361 | - 'roles', |
|
362 | - ], |
|
363 | - ], |
|
364 | - ], |
|
365 | - ], |
|
366 | - ]; |
|
367 | - } |
|
368 | -} |
@@ -26,343 +26,3 @@ |
||
26 | 26 | private string $userIsEnabledQuery = 'query ($hasAccess: Boolean = true) { user { isEnabled(hasAccess: $hasAccess) } }'; |
27 | 27 | |
28 | 28 | private string $userFriendsQuery = <<<'QUERY' |
29 | - query { |
|
30 | - user { |
|
31 | - friends(first: 2) { |
|
32 | - edges { |
|
33 | - node { |
|
34 | - name |
|
35 | - } |
|
36 | - } |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - QUERY; |
|
41 | - |
|
42 | - private string $simpleMutationWithThunkQuery = <<<'MUTATION' |
|
43 | - mutation M { |
|
44 | - simpleMutationWithThunkFields(input: {inputData: %d, clientMutationId: "bac"}) { |
|
45 | - result |
|
46 | - clientMutationId |
|
47 | - } |
|
48 | - } |
|
49 | - MUTATION; |
|
50 | - |
|
51 | - public function setUp(): void |
|
52 | - { |
|
53 | - parent::setUp(); |
|
54 | - // load types |
|
55 | - $this->loader = function ($class): void { |
|
56 | - if (preg_match('@^'.preg_quote('Overblog\GraphQLBundle\Access\__DEFINITIONS__\\').'(.*)$@', $class, $matches)) { |
|
57 | - $file = sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/access/cache/testaccess/overblog/graphql-bundle/__definitions__/'.$matches[1].'.php'; |
|
58 | - if (file_exists($file)) { |
|
59 | - require $file; |
|
60 | - } |
|
61 | - } |
|
62 | - }; |
|
63 | - spl_autoload_register($this->loader); |
|
64 | - } |
|
65 | - |
|
66 | - public function testCustomClassLoaderNotRegister(): void |
|
67 | - { |
|
68 | - $this->expectException(Error::class); |
|
69 | - if ((int) phpversion() <= 7) { |
|
70 | - $this->expectExceptionMessage('Class \'Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType\' not found'); |
|
71 | - } else { |
|
72 | - $this->expectExceptionMessage('Class "Overblog\GraphQLBundle\Access\__DEFINITIONS__\RootQueryType" not found'); |
|
73 | - } |
|
74 | - spl_autoload_unregister($this->loader); |
|
75 | - $this->assertResponse($this->userNameQuery, [], static::ANONYMOUS_USER, 'access'); |
|
76 | - } |
|
77 | - |
|
78 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledTrue(): void |
|
79 | - { |
|
80 | - $this->assertResponse( |
|
81 | - $this->userIsEnabledQuery, |
|
82 | - ['data' => ['user' => ['isEnabled' => true]]], |
|
83 | - static::ANONYMOUS_USER, |
|
84 | - 'access' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - public function testNotAuthenticatedUserAccessAsPromisedFulfilledFalse(): void |
|
89 | - { |
|
90 | - $this->assertResponse( |
|
91 | - $this->userIsEnabledQuery, |
|
92 | - [ |
|
93 | - 'data' => [ |
|
94 | - 'user' => [ |
|
95 | - 'isEnabled' => null, |
|
96 | - ], |
|
97 | - ], |
|
98 | - 'extensions' => [ |
|
99 | - 'warnings' => [ |
|
100 | - [ |
|
101 | - 'message' => 'Access denied to this field.', |
|
102 | - 'locations' => [['line' => 1, 'column' => 45]], |
|
103 | - 'path' => ['user', 'isEnabled'], |
|
104 | - ], |
|
105 | - ], |
|
106 | - ], |
|
107 | - ], |
|
108 | - static::ANONYMOUS_USER, |
|
109 | - 'access', |
|
110 | - '', |
|
111 | - ['hasAccess' => false] |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - public function testNotAuthenticatedUserAccessToUserName(): void |
|
116 | - { |
|
117 | - $expected = [ |
|
118 | - 'data' => [ |
|
119 | - 'user' => [ |
|
120 | - 'name' => null, |
|
121 | - ], |
|
122 | - ], |
|
123 | - 'extensions' => [ |
|
124 | - 'warnings' => [ |
|
125 | - [ |
|
126 | - 'message' => 'Access denied to this field.', |
|
127 | - 'locations' => [['line' => 1, 'column' => 16]], |
|
128 | - 'path' => ['user', 'name'], |
|
129 | - ], |
|
130 | - ], |
|
131 | - ], |
|
132 | - ]; |
|
133 | - |
|
134 | - $this->assertResponse($this->userNameQuery, $expected, static::ANONYMOUS_USER, 'access'); |
|
135 | - } |
|
136 | - |
|
137 | - public function testNonAuthenticatedUserAccessSecuredFieldWhichInitiallyResolvesToArray(): void |
|
138 | - { |
|
139 | - $expected = [ |
|
140 | - 'data' => [ |
|
141 | - 'youShallNotSeeThisUnauthenticated' => null, |
|
142 | - ], |
|
143 | - 'extensions' => [ |
|
144 | - 'warnings' => [ |
|
145 | - [ |
|
146 | - 'message' => 'Access denied to this field.', |
|
147 | - 'locations' => [ |
|
148 | - [ |
|
149 | - 'line' => 2, |
|
150 | - 'column' => 3, |
|
151 | - ], |
|
152 | - ], |
|
153 | - 'path' => ['youShallNotSeeThisUnauthenticated'], |
|
154 | - ], |
|
155 | - ], |
|
156 | - ], |
|
157 | - ]; |
|
158 | - |
|
159 | - $query = <<<'QUERY' |
|
160 | - { |
|
161 | - youShallNotSeeThisUnauthenticated { |
|
162 | - secretValue |
|
163 | - youAreAuthenticated |
|
164 | - } |
|
165 | - } |
|
166 | - QUERY; |
|
167 | - |
|
168 | - $this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'access'); |
|
169 | - } |
|
170 | - |
|
171 | - public function testFullyAuthenticatedUserAccessToUserName(): void |
|
172 | - { |
|
173 | - $expected = [ |
|
174 | - 'data' => [ |
|
175 | - 'user' => [ |
|
176 | - 'name' => 'Dan', |
|
177 | - ], |
|
178 | - ], |
|
179 | - ]; |
|
180 | - |
|
181 | - $this->assertResponse($this->userNameQuery, $expected, static::USER_RYAN, 'access'); |
|
182 | - } |
|
183 | - |
|
184 | - public function testNotAuthenticatedUserAccessToUserRoles(): void |
|
185 | - { |
|
186 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::ANONYMOUS_USER, 'access'); |
|
187 | - } |
|
188 | - |
|
189 | - public function testAuthenticatedUserAccessToUserRolesWithoutEnoughRights(): void |
|
190 | - { |
|
191 | - $this->assertResponse($this->userRolesQuery, $this->expectedFailedUserRoles(), static::USER_RYAN, 'access'); |
|
192 | - } |
|
193 | - |
|
194 | - public function testUserWithCorrectRightsAccessToUserRoles(): void |
|
195 | - { |
|
196 | - $expected = [ |
|
197 | - 'data' => [ |
|
198 | - 'user' => [ |
|
199 | - 'roles' => ['ROLE_USER'], |
|
200 | - ], |
|
201 | - ], |
|
202 | - ]; |
|
203 | - |
|
204 | - $this->assertResponse($this->userRolesQuery, $expected, static::USER_ADMIN, 'access'); |
|
205 | - } |
|
206 | - |
|
207 | - public function testUserForbiddenField(): void |
|
208 | - { |
|
209 | - $expected = [ |
|
210 | - 'data' => [ |
|
211 | - 'user' => null, |
|
212 | - ], |
|
213 | - 'extensions' => [ |
|
214 | - 'warnings' => [ |
|
215 | - [ |
|
216 | - 'message' => 'Access denied to this field.', |
|
217 | - 'locations' => [ |
|
218 | - [ |
|
219 | - 'line' => 3, |
|
220 | - 'column' => 5, |
|
221 | - ], |
|
222 | - ], |
|
223 | - 'path' => ['user', 'forbidden'], |
|
224 | - ], |
|
225 | - ], |
|
226 | - ], |
|
227 | - ]; |
|
228 | - |
|
229 | - $query = <<<'QUERY' |
|
230 | - query MyQuery { |
|
231 | - user { |
|
232 | - forbidden |
|
233 | - } |
|
234 | - } |
|
235 | - QUERY; |
|
236 | - |
|
237 | - $this->assertResponse($query, $expected, static::USER_ADMIN, 'access'); |
|
238 | - } |
|
239 | - |
|
240 | - public function testUserAccessToUserFriends(): void |
|
241 | - { |
|
242 | - $expected = [ |
|
243 | - 'data' => [ |
|
244 | - 'user' => [ |
|
245 | - 'friends' => [ |
|
246 | - 'edges' => [ |
|
247 | - ['node' => ['name' => 'Nick']], |
|
248 | - ['node' => null], |
|
249 | - ], |
|
250 | - ], |
|
251 | - ], |
|
252 | - ], |
|
253 | - ]; |
|
254 | - |
|
255 | - $this->assertResponse($this->userFriendsQuery, $expected, static::USER_ADMIN, 'access'); |
|
256 | - } |
|
257 | - |
|
258 | - public function testUserAccessToUserFriendsAsArray(): void |
|
259 | - { |
|
260 | - $expected = [ |
|
261 | - 'data' => [ |
|
262 | - 'user' => [ |
|
263 | - 'friendsAsArray' => [1, null, 3], |
|
264 | - ], |
|
265 | - ], |
|
266 | - ]; |
|
267 | - |
|
268 | - $this->assertResponse('query { user { friendsAsArray } }', $expected, static::USER_ADMIN, 'access'); |
|
269 | - } |
|
270 | - |
|
271 | - public function testMutationAllowedUser(): void |
|
272 | - { |
|
273 | - $result = 123; |
|
274 | - |
|
275 | - $expected = [ |
|
276 | - 'data' => [ |
|
277 | - 'simpleMutationWithThunkFields' => [ |
|
278 | - 'result' => $result, |
|
279 | - 'clientMutationId' => 'bac', |
|
280 | - ], |
|
281 | - ], |
|
282 | - ]; |
|
283 | - |
|
284 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, $result), $expected, static::USER_ADMIN, 'access'); |
|
285 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
286 | - } |
|
287 | - |
|
288 | - public function testMutationAllowedButNoRightsToDisplayPayload(): void |
|
289 | - { |
|
290 | - $expected = [ |
|
291 | - 'data' => [ |
|
292 | - 'simpleMutationWithThunkFields' => [ |
|
293 | - 'result' => null, |
|
294 | - 'clientMutationId' => 'bac', |
|
295 | - ], |
|
296 | - ], |
|
297 | - 'extensions' => [ |
|
298 | - 'warnings' => [ |
|
299 | - [ |
|
300 | - 'message' => 'Access denied to this field.', |
|
301 | - 'locations' => [ |
|
302 | - [ |
|
303 | - 'line' => 3, |
|
304 | - 'column' => 5, |
|
305 | - ], |
|
306 | - ], |
|
307 | - 'path' => ['simpleMutationWithThunkFields', 'result'], |
|
308 | - ], |
|
309 | - ], |
|
310 | - ], |
|
311 | - ]; |
|
312 | - |
|
313 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 321), $expected, static::USER_ADMIN, 'access'); |
|
314 | - $this->assertTrue(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
315 | - } |
|
316 | - |
|
317 | - public function testMutationNotAllowedUser(): void |
|
318 | - { |
|
319 | - $expected = [ |
|
320 | - 'errors' => [ |
|
321 | - [ |
|
322 | - 'message' => 'Access denied to this field.', |
|
323 | - 'locations' => [ |
|
324 | - [ |
|
325 | - 'line' => 2, |
|
326 | - 'column' => 3, |
|
327 | - ], |
|
328 | - ], |
|
329 | - 'path' => ['simpleMutationWithThunkFields'], |
|
330 | - ], |
|
331 | - ], |
|
332 | - 'data' => [ |
|
333 | - 'simpleMutationWithThunkFields' => null, |
|
334 | - ], |
|
335 | - ]; |
|
336 | - |
|
337 | - $this->assertResponse(sprintf($this->simpleMutationWithThunkQuery, 123), $expected, static::USER_RYAN, 'access'); |
|
338 | - $this->assertFalse(SimpleMutationWithThunkFieldsMutation::hasMutate(true)); |
|
339 | - } |
|
340 | - |
|
341 | - private function expectedFailedUserRoles(): array |
|
342 | - { |
|
343 | - return [ |
|
344 | - 'data' => [ |
|
345 | - 'user' => [ |
|
346 | - 'roles' => null, |
|
347 | - ], |
|
348 | - ], |
|
349 | - 'extensions' => [ |
|
350 | - 'warnings' => [ |
|
351 | - [ |
|
352 | - 'message' => 'Access denied to this field.', |
|
353 | - 'locations' => [ |
|
354 | - [ |
|
355 | - 'line' => 1, |
|
356 | - 'column' => 16, |
|
357 | - ], |
|
358 | - ], |
|
359 | - 'path' => [ |
|
360 | - 'user', |
|
361 | - 'roles', |
|
362 | - ], |
|
363 | - ], |
|
364 | - ], |
|
365 | - ], |
|
366 | - ]; |
|
367 | - } |
|
368 | -} |
@@ -18,28 +18,3 @@ |
||
18 | 18 | public function testExceptionIsMappedToAWarning(): void |
19 | 19 | { |
20 | 20 | $query = <<<'EOF' |
21 | - query ExceptionQuery { |
|
22 | - test |
|
23 | - } |
|
24 | - EOF; |
|
25 | - |
|
26 | - $expectedData = [ |
|
27 | - 'test' => null, |
|
28 | - ]; |
|
29 | - |
|
30 | - $expectedErrors = [ |
|
31 | - [ |
|
32 | - 'message' => 'Invalid argument exception', |
|
33 | - 'locations' => [ |
|
34 | - [ |
|
35 | - 'line' => 2, |
|
36 | - 'column' => 5, |
|
37 | - ], |
|
38 | - ], |
|
39 | - 'path' => ['test'], |
|
40 | - ], |
|
41 | - ]; |
|
42 | - |
|
43 | - $this->assertGraphQL($query, $expectedData, $expectedErrors); |
|
44 | - } |
|
45 | -} |
@@ -18,28 +18,3 @@ |
||
18 | 18 | public function testExceptionIsMappedToAWarning(): void |
19 | 19 | { |
20 | 20 | $query = <<<'EOF' |
21 | - query ExceptionQuery { |
|
22 | - test |
|
23 | - } |
|
24 | - EOF; |
|
25 | - |
|
26 | - $expectedData = [ |
|
27 | - 'test' => null, |
|
28 | - ]; |
|
29 | - |
|
30 | - $expectedErrors = [ |
|
31 | - [ |
|
32 | - 'message' => 'Invalid argument exception', |
|
33 | - 'locations' => [ |
|
34 | - [ |
|
35 | - 'line' => 2, |
|
36 | - 'column' => 5, |
|
37 | - ], |
|
38 | - ], |
|
39 | - 'path' => ['test'], |
|
40 | - ], |
|
41 | - ]; |
|
42 | - |
|
43 | - $this->assertGraphQL($query, $expectedData, $expectedErrors); |
|
44 | - } |
|
45 | -} |
@@ -18,28 +18,3 @@ |
||
18 | 18 | public function testExceptionIsMappedToAWarning(): void |
19 | 19 | { |
20 | 20 | $query = <<<'EOF' |
21 | - query ExceptionQuery { |
|
22 | - test |
|
23 | - } |
|
24 | - EOF; |
|
25 | - |
|
26 | - $expectedData = [ |
|
27 | - 'test' => null, |
|
28 | - ]; |
|
29 | - |
|
30 | - $expectedErrors = [ |
|
31 | - [ |
|
32 | - 'message' => 'Invalid argument exception', |
|
33 | - 'locations' => [ |
|
34 | - [ |
|
35 | - 'line' => 2, |
|
36 | - 'column' => 5, |
|
37 | - ], |
|
38 | - ], |
|
39 | - 'path' => ['test'], |
|
40 | - ], |
|
41 | - ]; |
|
42 | - |
|
43 | - $this->assertGraphQL($query, $expectedData, $expectedErrors); |
|
44 | - } |
|
45 | -} |
@@ -18,28 +18,3 @@ |
||
18 | 18 | public function testExceptionIsMappedToAWarning(): void |
19 | 19 | { |
20 | 20 | $query = <<<'EOF' |
21 | - query ExceptionQuery { |
|
22 | - test |
|
23 | - } |
|
24 | - EOF; |
|
25 | - |
|
26 | - $expectedData = [ |
|
27 | - 'test' => null, |
|
28 | - ]; |
|
29 | - |
|
30 | - $expectedErrors = [ |
|
31 | - [ |
|
32 | - 'message' => 'Invalid argument exception', |
|
33 | - 'locations' => [ |
|
34 | - [ |
|
35 | - 'line' => 2, |
|
36 | - 'column' => 5, |
|
37 | - ], |
|
38 | - ], |
|
39 | - 'path' => ['test'], |
|
40 | - ], |
|
41 | - ]; |
|
42 | - |
|
43 | - $this->assertGraphQL($query, $expectedData, $expectedErrors); |
|
44 | - } |
|
45 | -} |
@@ -18,28 +18,3 @@ |
||
18 | 18 | public function testExceptionIsMappedToAWarning(): void |
19 | 19 | { |
20 | 20 | $query = <<<'EOF' |
21 | - query ExceptionQuery { |
|
22 | - test |
|
23 | - } |
|
24 | - EOF; |
|
25 | - |
|
26 | - $expectedData = [ |
|
27 | - 'test' => null, |
|
28 | - ]; |
|
29 | - |
|
30 | - $expectedErrors = [ |
|
31 | - [ |
|
32 | - 'message' => 'Invalid argument exception', |
|
33 | - 'locations' => [ |
|
34 | - [ |
|
35 | - 'line' => 2, |
|
36 | - 'column' => 5, |
|
37 | - ], |
|
38 | - ], |
|
39 | - 'path' => ['test'], |
|
40 | - ], |
|
41 | - ]; |
|
42 | - |
|
43 | - $this->assertGraphQL($query, $expectedData, $expectedErrors); |
|
44 | - } |
|
45 | -} |