2021-03-12 18:00:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\GraphQL;
|
|
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
2022-04-08 13:52:20 +00:00
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
2021-03-12 18:00:41 +00:00
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
|
use Tests\E2E\Scopes\SideServer;
|
|
|
|
|
|
2021-03-16 13:34:11 +00:00
|
|
|
|
2022-04-08 13:52:20 +00:00
|
|
|
class GraphQLServerTest extends Scope
|
2021-03-12 18:00:41 +00:00
|
|
|
{
|
2022-04-08 13:52:20 +00:00
|
|
|
use ProjectCustom;
|
2021-03-12 18:00:41 +00:00
|
|
|
use SideServer;
|
2021-03-16 14:34:43 +00:00
|
|
|
use GraphQLBase;
|
2021-03-12 18:00:41 +00:00
|
|
|
|
2022-04-08 13:52:20 +00:00
|
|
|
public function testScopeBasedAuth()
|
|
|
|
|
{
|
|
|
|
|
$key = $this->getNewKey(['locale.read']);
|
2021-03-16 13:34:11 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2022-04-08 13:52:20 +00:00
|
|
|
|
2021-03-18 20:17:25 +00:00
|
|
|
/**
|
|
|
|
|
* Check that countries can be fetched
|
|
|
|
|
*/
|
2021-03-16 18:16:33 +00:00
|
|
|
$query = $this->getQuery(self::$LIST_COUNTRIES);
|
2021-03-16 13:34:11 +00:00
|
|
|
$variables = [];
|
|
|
|
|
$graphQLPayload = [
|
2022-04-08 13:52:20 +00:00
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => $variables
|
2021-03-16 13:34:11 +00:00
|
|
|
];
|
|
|
|
|
$countries = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
'x-appwrite-key' => $key
|
|
|
|
|
], $graphQLPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($countries['body']['data']);
|
2022-04-08 13:52:20 +00:00
|
|
|
$this->assertIsArray($countries['body']['data']['localeGetCountries']);
|
|
|
|
|
|
|
|
|
|
$data = $countries['body']['data']['localeGetCountries'];
|
2021-03-16 13:34:11 +00:00
|
|
|
$this->assertEquals(194, count($data['countries']));
|
2022-04-08 13:52:20 +00:00
|
|
|
$this->assertEquals(194, $data['total']);
|
2021-03-16 13:34:11 +00:00
|
|
|
|
2021-03-16 18:16:33 +00:00
|
|
|
|
2021-03-18 20:17:25 +00:00
|
|
|
/**
|
2022-05-02 09:34:10 +00:00
|
|
|
* Create a key without any scopes
|
2021-03-18 20:17:25 +00:00
|
|
|
*/
|
2022-04-08 13:52:20 +00:00
|
|
|
$key = $this->getNewKey([]);
|
2021-03-16 13:34:11 +00:00
|
|
|
$countries = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
'x-appwrite-key' => $key
|
|
|
|
|
], $graphQLPayload);
|
|
|
|
|
|
2022-06-27 06:46:01 +00:00
|
|
|
$errorMessage = 'app.' . $projectId . '@service.localhost (role: application) missing scope (locale.read)';
|
|
|
|
|
$this->assertEquals(401, $countries['headers']['status-code']);
|
2021-03-16 13:34:11 +00:00
|
|
|
$this->assertEquals($countries['body']['errors'][0]['message'], $errorMessage);
|
|
|
|
|
$this->assertIsArray($countries['body']['data']);
|
2022-06-27 06:46:01 +00:00
|
|
|
$this->assertNull($countries['body']['data']['localeGetCountries']);
|
2021-03-12 20:17:29 +00:00
|
|
|
}
|
2021-03-12 18:00:41 +00:00
|
|
|
|
|
|
|
|
}
|