From 0f2cb5ed0ddf16048a34934ce1dda6c5bf41a437 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 13 Jul 2022 19:38:23 +1200 Subject: [PATCH] Add scope specific tests --- .../e2e/Services/GraphQL/GraphQLScopeTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/e2e/Services/GraphQL/GraphQLScopeTest.php diff --git a/tests/e2e/Services/GraphQL/GraphQLScopeTest.php b/tests/e2e/Services/GraphQL/GraphQLScopeTest.php new file mode 100644 index 0000000000..6af2a5b50f --- /dev/null +++ b/tests/e2e/Services/GraphQL/GraphQLScopeTest.php @@ -0,0 +1,65 @@ +getProject()['$id']; + $apiKey = $this->getNewKey(['databases.read']); + $query = $this->getQuery(self::$CREATE_DATABASE); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'databaseId' => 'unique()', + 'name' => 'Actors', + ] + ]; + + $database = $this->client->call(Client::METHOD_POST, '/graphql', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], $gqlPayload); + + $message = "app.${projectId}@service.localhost (role: application) missing scope (databases.write)"; + $this->assertArrayHasKey('errors', $database['body']); + $this->assertEquals($message, $database['body']['errors'][0]['message']); + } + + public function testValidScope() + { + $projectId = $this->getProject()['$id']; + $apiKey = $this->getNewKey(['databases.read', 'databases.write']); + $query = $this->getQuery(self::$CREATE_DATABASE); + $gqlPayload = [ + 'query' => $query, + 'variables' => [ + 'databaseId' => 'unique()', + 'name' => 'Actors', + ] + ]; + + $database = $this->client->call(Client::METHOD_POST, '/graphql', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], $gqlPayload); + + $this->assertIsArray($database['body']['data']); + $this->assertArrayNotHasKey('errors', $database['body']); + $database = $database['body']['data']['databasesCreate']; + $this->assertEquals('Actors', $database['name']); + } +}