We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -81,6 +81,4 @@ |
||
| 81 | 81 | $reactAdapter->convertThenable($promise); |
| 82 | 82 | |
| 83 | 83 | $this->assertInstanceOf(Promise::class, $promise); |
| 84 | - $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise); // @phpstan-ignore-line |
|
| 85 | - } |
|
| 86 | -} |
|
| 84 | + $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise |
|
| 87 | 85 | \ No newline at end of file |
@@ -81,6 +81,4 @@ |
||
| 81 | 81 | $reactAdapter->convertThenable($promise); |
| 82 | 82 | |
| 83 | 83 | $this->assertInstanceOf(Promise::class, $promise); |
| 84 | - $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise); // @phpstan-ignore-line |
|
| 85 | - } |
|
| 86 | -} |
|
| 84 | + $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise |
|
| 87 | 85 | \ No newline at end of file |
@@ -81,6 +81,4 @@ |
||
| 81 | 81 | $reactAdapter->convertThenable($promise); |
| 82 | 82 | |
| 83 | 83 | $this->assertInstanceOf(Promise::class, $promise); |
| 84 | - $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise); // @phpstan-ignore-line |
|
| 85 | - } |
|
| 86 | -} |
|
| 84 | + $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise |
|
| 87 | 85 | \ No newline at end of file |
@@ -81,6 +81,4 @@ |
||
| 81 | 81 | $reactAdapter->convertThenable($promise); |
| 82 | 82 | |
| 83 | 83 | $this->assertInstanceOf(Promise::class, $promise); |
| 84 | - $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise); // @phpstan-ignore-line |
|
| 85 | - } |
|
| 86 | -} |
|
| 84 | + $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise |
|
| 87 | 85 | \ No newline at end of file |
@@ -81,6 +81,4 @@ |
||
| 81 | 81 | $reactAdapter->convertThenable($promise); |
| 82 | 82 | |
| 83 | 83 | $this->assertInstanceOf(Promise::class, $promise); |
| 84 | - $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise); // @phpstan-ignore-line |
|
| 85 | - } |
|
| 86 | -} |
|
| 84 | + $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise |
|
| 87 | 85 | \ No newline at end of file |
@@ -293,7 +293,7 @@ |
||
| 293 | 293 | 'type' => 'Int!', |
| 294 | 294 | 'defaultValue' => 0, |
| 295 | 295 | ], |
| 296 | - ], |
|
| 296 | + ], |
|
| 297 | 297 | ], |
| 298 | 298 | ], |
| 299 | 299 | 'name' => 'foo', |
@@ -106,13 +106,13 @@ |
||
| 106 | 106 | protected function createGraphQLServices(array $services = []): GraphQLServices |
| 107 | 107 | { |
| 108 | 108 | $locateableServices = [ |
| 109 | - 'typeResolver' => fn () => $this->createMock(TypeResolver::class), |
|
| 110 | - 'queryResolver' => fn () => $this->createMock(TypeResolver::class), |
|
| 111 | - 'mutationResolver' => fn () => $$this->createMock(MutationResolver::class), |
|
| 109 | + 'typeResolver' => fn() => $this->createMock(TypeResolver::class), |
|
| 110 | + 'queryResolver' => fn() => $this->createMock(TypeResolver::class), |
|
| 111 | + 'mutationResolver' => fn() => $$this->createMock(MutationResolver::class), |
|
| 112 | 112 | ]; |
| 113 | 113 | |
| 114 | 114 | foreach ($services as $id => $service) { |
| 115 | - $locateableServices[$id] = fn () => $service; |
|
| 115 | + $locateableServices[$id] = fn() => $service; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | return new GraphQLServices($locateableServices); |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | public function testScalarTypeConfig(): void |
| 23 | 23 | { |
| 24 | 24 | $this->assertScalarTypeConfig(new YearScalarType()); |
| 25 | - $this->assertScalarTypeConfig(fn () => new YearScalarType()); |
|
| 25 | + $this->assertScalarTypeConfig(fn() => new YearScalarType()); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function testWithoutScalarTypeConfig(): void |
| 29 | 29 | { |
| 30 | - $genericFunc = fn ($value) => $value; |
|
| 30 | + $genericFunc = fn($value) => $value; |
|
| 31 | 31 | $type = new CustomScalarType([ |
| 32 | 32 | 'serialize' => $genericFunc, |
| 33 | 33 | 'parseValue' => $genericFunc, |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | yield [false, 'false']; |
| 75 | 75 | yield [new stdClass(), 'instance of stdClass']; |
| 76 | 76 | yield [ |
| 77 | - fn () => false, |
|
| 77 | + fn() => false, |
|
| 78 | 78 | 'false', |
| 79 | 79 | ]; |
| 80 | 80 | yield [ |
| 81 | - fn () => new stdClass(), |
|
| 81 | + fn() => new stdClass(), |
|
| 82 | 82 | 'instance of stdClass', |
| 83 | 83 | ]; |
| 84 | 84 | } |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | $type = new CustomScalarType([ |
| 94 | 94 | 'scalarType' => $scalarType, |
| 95 | - 'serialize' => fn () => 'serialize', |
|
| 96 | - 'parseValue' => fn () => 'parseValue', |
|
| 97 | - 'parseLiteral' => fn () => 'parseLiteral', |
|
| 95 | + 'serialize' => fn() => 'serialize', |
|
| 96 | + 'parseValue' => fn() => 'parseValue', |
|
| 97 | + 'parseLiteral' => fn() => 'parseLiteral', |
|
| 98 | 98 | ]); |
| 99 | 99 | |
| 100 | 100 | $this->assertSame('50 AC', $type->serialize(50)); |
@@ -281,6 +281,4 @@ |
||
| 281 | 281 | ], |
| 282 | 282 | ]; |
| 283 | 283 | |
| 284 | - $this->assertGraphQL($query, $expectedData); |
|
| 285 | - } |
|
| 286 | -} |
|
| 284 | + $this->assertGraphQL($query, $expectedData |
|
| 287 | 285 | \ No newline at end of file |
@@ -281,6 +281,4 @@ |
||
| 281 | 281 | ], |
| 282 | 282 | ]; |
| 283 | 283 | |
| 284 | - $this->assertGraphQL($query, $expectedData); |
|
| 285 | - } |
|
| 286 | -} |
|
| 284 | + $this->assertGraphQL($query, $expectedData |
|
| 287 | 285 | \ No newline at end of file |
@@ -281,6 +281,4 @@ |
||
| 281 | 281 | ], |
| 282 | 282 | ]; |
| 283 | 283 | |
| 284 | - $this->assertGraphQL($query, $expectedData); |
|
| 285 | - } |
|
| 286 | -} |
|
| 284 | + $this->assertGraphQL($query, $expectedData |
|
| 287 | 285 | \ No newline at end of file |
@@ -281,6 +281,4 @@ |
||
| 281 | 281 | ], |
| 282 | 282 | ]; |
| 283 | 283 | |
| 284 | - $this->assertGraphQL($query, $expectedData); |
|
| 285 | - } |
|
| 286 | -} |
|
| 284 | + $this->assertGraphQL($query, $expectedData |
|
| 287 | 285 | \ No newline at end of file |
@@ -281,6 +281,4 @@ |
||
| 281 | 281 | ], |
| 282 | 282 | ]; |
| 283 | 283 | |
| 284 | - $this->assertGraphQL($query, $expectedData); |
|
| 285 | - } |
|
| 286 | -} |
|
| 284 | + $this->assertGraphQL($query, $expectedData |
|
| 287 | 285 | \ No newline at end of file |
@@ -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 | -} |
|
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public function testSpecialField($fieldName, ObjectType | UnionType | InterfaceType | CustomScalarType $typeWithSpecialField, callable $fieldValueRetriever = null, $strict = true): void |
| 34 | 34 | { |
| 35 | 35 | if (null === $fieldValueRetriever) { |
| 36 | - $fieldValueRetriever = fn (ObjectType | UnionType | InterfaceType | CustomScalarType $type, $fieldName) => $type->config[$fieldName]; |
|
| 36 | + $fieldValueRetriever = fn(ObjectType | UnionType | InterfaceType | CustomScalarType $type, $fieldName) => $type->config[$fieldName]; |
|
| 37 | 37 | } |
| 38 | 38 | $expected = static function (): void { |
| 39 | 39 | }; |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | ]; |
| 67 | 67 | }, |
| 68 | 68 | ]); |
| 69 | - $barResolver = static fn () => 'bar'; |
|
| 70 | - $bazResolver = static fn () => 'baz'; |
|
| 69 | + $barResolver = static fn() => 'bar'; |
|
| 70 | + $bazResolver = static fn() => 'baz'; |
|
| 71 | 71 | |
| 72 | 72 | $this->decorate( |
| 73 | 73 | [$objectType->name => $objectType], |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | [$objectType->name => $objectType], |
| 101 | 101 | [ |
| 102 | 102 | $objectType->name => [ |
| 103 | - 'bar' => fn ($value, $args) => $args, |
|
| 103 | + 'bar' => fn($value, $args) => $args, |
|
| 104 | 104 | ], |
| 105 | 105 | ] |
| 106 | 106 | ); |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | [ |
| 251 | 251 | ResolverMapInterface::RESOLVE_FIELD, |
| 252 | 252 | $objectWithResolveField, |
| 253 | - fn (ObjectType $type) => $type->resolveFieldFn, |
|
| 253 | + fn(ObjectType $type) => $type->resolveFieldFn, |
|
| 254 | 254 | false, |
| 255 | 255 | ], |
| 256 | 256 | [ResolverMapInterface::RESOLVE_FIELD, $objectWithResolveField, null, false], |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | ?string $type = null, |
| 35 | 35 | ?string $resolve = null, |
| 36 | 36 | ?string $complexity = null, |
| 37 | - array|string|null $targetTypes = null |
|
| 37 | + array | string | null $targetTypes = null |
|
| 38 | 38 | ) { |
| 39 | 39 | parent::__construct($name, $type, $resolve, $complexity); |
| 40 | 40 | if ($targetTypes) { |