mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add tests
This commit is contained in:
@@ -427,7 +427,7 @@ App::init()
|
||||
->addHeader('Server', 'Appwrite')
|
||||
->addHeader('X-Content-Type-Options', 'nosniff')
|
||||
->addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE')
|
||||
->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-Appwrite-JWT, X-Appwrite-Response-Format, X-Appwrite-Timeout, X-SDK-Version, X-SDK-Name, X-SDK-Language, X-SDK-Platform, X-SDK-GraphQL, X-Appwrite-ID, X-Appwrite-Timestamp, Content-Range, Range, Cache-Control, Expires, Pragma')
|
||||
->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-Appwrite-JWT, X-Appwrite-Response-Format, X-Appwrite-Timeout, X-Appwrite-Share-Tables, X-SDK-Version, X-SDK-Name, X-SDK-Language, X-SDK-Platform, X-SDK-GraphQL, X-Appwrite-ID, X-Appwrite-Timestamp, Content-Range, Range, Cache-Control, Expires, Pragma')
|
||||
->addHeader('Access-Control-Expose-Headers', 'X-Fallback-Cookies')
|
||||
->addHeader('Access-Control-Allow-Origin', $refDomain)
|
||||
->addHeader('Access-Control-Allow-Credentials', 'true');
|
||||
@@ -591,7 +591,7 @@ App::options()
|
||||
$response
|
||||
->addHeader('Server', 'Appwrite')
|
||||
->addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE')
|
||||
->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-Appwrite-JWT, X-Appwrite-Response-Format, X-Appwrite-Timeout, X-SDK-Version, X-SDK-Name, X-SDK-Language, X-SDK-Platform, X-SDK-GraphQL, X-Appwrite-ID, X-Appwrite-Timestamp, Content-Range, Range, Cache-Control, Expires, Pragma, X-Fallback-Cookies')
|
||||
->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-Appwrite-JWT, X-Appwrite-Response-Format, X-Appwrite-Timeout, X-Appwrite-Share-Tables, X-SDK-Version, X-SDK-Name, X-SDK-Language, X-SDK-Platform, X-SDK-GraphQL, X-Appwrite-ID, X-Appwrite-Timestamp, Content-Range, Range, Cache-Control, Expires, Pragma, X-Fallback-Cookies')
|
||||
->addHeader('Access-Control-Expose-Headers', 'X-Fallback-Cookies')
|
||||
->addHeader('Access-Control-Allow-Origin', $origin)
|
||||
->addHeader('Access-Control-Allow-Credentials', 'true')
|
||||
|
||||
@@ -8,6 +8,7 @@ use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectConsole;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
|
||||
@@ -3294,4 +3295,473 @@ class ProjectsConsoleClientTest extends Scope
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testTenantIsolation(): void
|
||||
{
|
||||
// Create a team and a project
|
||||
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'teamId' => ID::unique(),
|
||||
'name' => 'Amazing Team',
|
||||
]);
|
||||
|
||||
$teamId = $team['body']['$id'];
|
||||
|
||||
// Project-level isolation
|
||||
$project1 = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-share-tables' => false
|
||||
], $this->getHeaders()), [
|
||||
'projectId' => ID::unique(),
|
||||
'name' => 'Amazing Project',
|
||||
'teamId' => $teamId,
|
||||
'region' => 'default'
|
||||
]);
|
||||
|
||||
// Application level isolation (shared tables)
|
||||
$project2 = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-share-tables' => true
|
||||
], $this->getHeaders()), [
|
||||
'projectId' => ID::unique(),
|
||||
'name' => 'Amazing Project',
|
||||
'teamId' => $teamId,
|
||||
'region' => 'default'
|
||||
]);
|
||||
|
||||
// Project-level isolation
|
||||
$project3 = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-share-tables' => false
|
||||
], $this->getHeaders()), [
|
||||
'projectId' => ID::unique(),
|
||||
'name' => 'Amazing Project',
|
||||
'teamId' => $teamId,
|
||||
'region' => 'default'
|
||||
]);
|
||||
|
||||
// Application level isolation (shared tables)
|
||||
$project4 = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-share-tables' => true
|
||||
], $this->getHeaders()), [
|
||||
'projectId' => ID::unique(),
|
||||
'name' => 'Amazing Project',
|
||||
'teamId' => $teamId,
|
||||
'region' => 'default'
|
||||
]);
|
||||
|
||||
// Create and API key in each project
|
||||
$key1 = $this->client->call(Client::METHOD_POST, '/projects/' . $project1['body']['$id'] . '/keys', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Key Test',
|
||||
'scopes' => ['databases.read', 'databases.write', 'collections.read', 'collections.write', 'attributes.read', 'attributes.write', 'indexes.read', 'indexes.write', 'documents.read', 'documents.write'],
|
||||
]);
|
||||
|
||||
$key2 = $this->client->call(Client::METHOD_POST, '/projects/' . $project2['body']['$id'] . '/keys', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Key Test',
|
||||
'scopes' => ['databases.read', 'databases.write', 'collections.read', 'collections.write', 'attributes.read', 'attributes.write', 'indexes.read', 'indexes.write', 'documents.read', 'documents.write'],
|
||||
]);
|
||||
|
||||
$key3 = $this->client->call(Client::METHOD_POST, '/projects/' . $project3['body']['$id'] . '/keys', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Key Test',
|
||||
'scopes' => ['databases.read', 'databases.write', 'collections.read', 'collections.write', 'attributes.read', 'attributes.write', 'indexes.read', 'indexes.write', 'documents.read', 'documents.write'],
|
||||
]);
|
||||
|
||||
$key4 = $this->client->call(Client::METHOD_POST, '/projects/' . $project4['body']['$id'] . '/keys', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Key Test',
|
||||
'scopes' => ['databases.read', 'databases.write', 'collections.read', 'collections.write', 'attributes.read', 'attributes.write', 'indexes.read', 'indexes.write', 'documents.read', 'documents.write'],
|
||||
]);
|
||||
|
||||
// Create a database in each project
|
||||
$database1 = $this->client->call(Client::METHOD_POST, '/databases', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
], [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'Amazing Database',
|
||||
]);
|
||||
|
||||
$database2 = $this->client->call(Client::METHOD_POST, '/databases', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
], [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'Amazing Database',
|
||||
]);
|
||||
|
||||
$database3 = $this->client->call(Client::METHOD_POST, '/databases', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
], [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'Amazing Database',
|
||||
]);
|
||||
|
||||
$database4 = $this->client->call(Client::METHOD_POST, '/databases', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project4['body']['$id'],
|
||||
'x-appwrite-key' => $key4['body']['secret']
|
||||
], [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'Amazing Database',
|
||||
]);
|
||||
|
||||
// Create a collection in each project
|
||||
$collection1 = $this->client->call(Client::METHOD_POST, '/databases/' . $database1['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database1['body']['$id'],
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'Amazing Collection',
|
||||
]);
|
||||
|
||||
$collection2 = $this->client->call(Client::METHOD_POST, '/databases/' . $database2['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database2['body']['$id'],
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'Amazing Collection',
|
||||
]);
|
||||
|
||||
$collection3 = $this->client->call(Client::METHOD_POST, '/databases/' . $database3['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database3['body']['$id'],
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'Amazing Collection',
|
||||
]);
|
||||
|
||||
$collection4 = $this->client->call(Client::METHOD_POST, '/databases/' . $database4['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project4['body']['$id'],
|
||||
'x-appwrite-key' => $key4['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database4['body']['$id'],
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'Amazing Collection',
|
||||
]);
|
||||
|
||||
// Create an attribute in each project
|
||||
$attribute1 = $this->client->call(Client::METHOD_POST, '/databases/' . $database1['body']['$id'] . '/collections/' . $collection1['body']['$id'] . '/attributes/string', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database1['body']['$id'],
|
||||
'collectionId' => $collection1['body']['$id'],
|
||||
'key' => ID::unique(),
|
||||
'size' => 255,
|
||||
'required' => true
|
||||
]);
|
||||
|
||||
$attribute2 = $this->client->call(Client::METHOD_POST, '/databases/' . $database2['body']['$id'] . '/collections/' . $collection2['body']['$id'] . '/attributes/string', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database2['body']['$id'],
|
||||
'collectionId' => $collection2['body']['$id'],
|
||||
'key' => ID::unique(),
|
||||
'size' => 255,
|
||||
'required' => true
|
||||
]);
|
||||
|
||||
$attribute3 = $this->client->call(Client::METHOD_POST, '/databases/' . $database3['body']['$id'] . '/collections/' . $collection3['body']['$id'] . '/attributes/string', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database3['body']['$id'],
|
||||
'collectionId' => $collection3['body']['$id'],
|
||||
'key' => ID::unique(),
|
||||
'size' => 255,
|
||||
'required' => true
|
||||
]);
|
||||
|
||||
$attribute4 = $this->client->call(Client::METHOD_POST, '/databases/' . $database4['body']['$id'] . '/collections/' . $collection4['body']['$id'] . '/attributes/string', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project4['body']['$id'],
|
||||
'x-appwrite-key' => $key4['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database4['body']['$id'],
|
||||
'collectionId' => $collection4['body']['$id'],
|
||||
'key' => ID::unique(),
|
||||
'size' => 255,
|
||||
'required' => true
|
||||
]);
|
||||
|
||||
// Wait for attributes
|
||||
\sleep(2);
|
||||
|
||||
// Create an index in each project
|
||||
$index1 = $this->client->call(Client::METHOD_POST, '/databases/' . $database1['body']['$id'] . '/collections/' . $collection1['body']['$id'] . '/indexes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database1['body']['$id'],
|
||||
'collectionId' => $collection1['body']['$id'],
|
||||
'key' => ID::unique(),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => [$attribute1['body']['key']],
|
||||
]);
|
||||
|
||||
$index2 = $this->client->call(Client::METHOD_POST, '/databases/' . $database2['body']['$id'] . '/collections/' . $collection2['body']['$id'] . '/indexes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database2['body']['$id'],
|
||||
'collectionId' => $collection2['body']['$id'],
|
||||
'key' => ID::unique(),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => [$attribute2['body']['key']],
|
||||
]);
|
||||
|
||||
$index3 = $this->client->call(Client::METHOD_POST, '/databases/' . $database3['body']['$id'] . '/collections/' . $collection3['body']['$id'] . '/indexes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database3['body']['$id'],
|
||||
'collectionId' => $collection3['body']['$id'],
|
||||
'key' => ID::unique(),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => [$attribute3['body']['key']],
|
||||
]);
|
||||
|
||||
$index4 = $this->client->call(Client::METHOD_POST, '/databases/' . $database4['body']['$id'] . '/collections/' . $collection4['body']['$id'] . '/indexes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project4['body']['$id'],
|
||||
'x-appwrite-key' => $key4['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database4['body']['$id'],
|
||||
'collectionId' => $collection4['body']['$id'],
|
||||
'key' => ID::unique(),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => [$attribute4['body']['key']],
|
||||
]);
|
||||
|
||||
// Wait for indexes
|
||||
\sleep(2);
|
||||
|
||||
// Assert that each project has only 1 database, 1 collection, 1 attribute and 1 index
|
||||
$databasesProject1 = $this->client->call(Client::METHOD_GET, '/databases', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $databasesProject1['body']['total']);
|
||||
$this->assertEquals(1, \count($databasesProject1['body']['databases']));
|
||||
|
||||
$databasesProject2 = $this->client->call(Client::METHOD_GET, '/databases', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $databasesProject2['body']['total']);
|
||||
$this->assertEquals(1, \count($databasesProject2['body']['databases']));
|
||||
|
||||
$databasesProject3 = $this->client->call(Client::METHOD_GET, '/databases', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $databasesProject3['body']['total']);
|
||||
$this->assertEquals(1, \count($databasesProject3['body']['databases']));
|
||||
|
||||
$databasesProject4 = $this->client->call(Client::METHOD_GET, '/databases', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project4['body']['$id'],
|
||||
'x-appwrite-key' => $key4['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $databasesProject4['body']['total']);
|
||||
$this->assertEquals(1, \count($databasesProject4['body']['databases']));
|
||||
|
||||
$collectionsProject1 = $this->client->call(Client::METHOD_GET, '/databases/' . $database1['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $collectionsProject1['body']['total']);
|
||||
$this->assertEquals(1, \count($collectionsProject1['body']['collections']));
|
||||
|
||||
$collectionsProject2 = $this->client->call(Client::METHOD_GET, '/databases/' . $database2['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $collectionsProject2['body']['total']);
|
||||
$this->assertEquals(1, \count($collectionsProject2['body']['collections']));
|
||||
|
||||
$collectionsProject3 = $this->client->call(Client::METHOD_GET, '/databases/' . $database3['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $collectionsProject3['body']['total']);
|
||||
$this->assertEquals(1, \count($collectionsProject3['body']['collections']));
|
||||
|
||||
$collectionsProject4 = $this->client->call(Client::METHOD_GET, '/databases/' . $database4['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project4['body']['$id'],
|
||||
'x-appwrite-key' => $key4['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $collectionsProject4['body']['total']);
|
||||
$this->assertEquals(1, \count($collectionsProject4['body']['collections']));
|
||||
|
||||
$attributesProject1 = $this->client->call(Client::METHOD_GET, '/databases/' . $database1['body']['$id'] . '/collections/' . $collection1['body']['$id'] . '/attributes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $attributesProject1['body']['total']);
|
||||
$this->assertEquals(1, \count($attributesProject1['body']['attributes']));
|
||||
|
||||
$attributesProject2 = $this->client->call(Client::METHOD_GET, '/databases/' . $database2['body']['$id'] . '/collections/' . $collection2['body']['$id'] . '/attributes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $attributesProject2['body']['total']);
|
||||
$this->assertEquals(1, \count($attributesProject2['body']['attributes']));
|
||||
|
||||
$attributesProject3 = $this->client->call(Client::METHOD_GET, '/databases/' . $database3['body']['$id'] . '/collections/' . $collection3['body']['$id'] . '/attributes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $attributesProject3['body']['total']);
|
||||
$this->assertEquals(1, \count($attributesProject3['body']['attributes']));
|
||||
|
||||
$attributesProject4 = $this->client->call(Client::METHOD_GET, '/databases/' . $database4['body']['$id'] . '/collections/' . $collection4['body']['$id'] . '/attributes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project4['body']['$id'],
|
||||
'x-appwrite-key' => $key4['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $attributesProject4['body']['total']);
|
||||
$this->assertEquals(1, \count($attributesProject4['body']['attributes']));
|
||||
|
||||
$indexesProject1 = $this->client->call(Client::METHOD_GET, '/databases/' . $database1['body']['$id'] . '/collections/' . $collection1['body']['$id'] . '/indexes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $indexesProject1['body']['total']);
|
||||
$this->assertEquals(1, \count($indexesProject1['body']['indexes']));
|
||||
|
||||
$indexesProject2 = $this->client->call(Client::METHOD_GET, '/databases/' . $database2['body']['$id'] . '/collections/' . $collection2['body']['$id'] . '/indexes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $indexesProject2['body']['total']);
|
||||
$this->assertEquals(1, \count($indexesProject2['body']['indexes']));
|
||||
|
||||
$indexesProject3 = $this->client->call(Client::METHOD_GET, '/databases/' . $database3['body']['$id'] . '/collections/' . $collection3['body']['$id'] . '/indexes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $indexesProject3['body']['total']);
|
||||
$this->assertEquals(1, \count($indexesProject3['body']['indexes']));
|
||||
|
||||
$indexesProject4 = $this->client->call(Client::METHOD_GET, '/databases/' . $database4['body']['$id'] . '/collections/' . $collection4['body']['$id'] . '/indexes', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project4['body']['$id'],
|
||||
'x-appwrite-key' => $key4['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(1, $indexesProject4['body']['total']);
|
||||
$this->assertEquals(1, \count($indexesProject4['body']['indexes']));
|
||||
|
||||
// Attempt to read cross-type resources
|
||||
$collectionProject2WithProject1Key = $this->client->call(Client::METHOD_GET, '/databases/' . $database2['body']['$id'] . '/collections/' . $collection2['body']['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(404, $collectionProject2WithProject1Key['headers']['status-code']);
|
||||
|
||||
$collectionProject1WithProject2Key = $this->client->call(Client::METHOD_GET, '/databases/' . $database1['body']['$id'] . '/collections/' . $collection1['body']['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(404, $collectionProject1WithProject2Key['headers']['status-code']);
|
||||
|
||||
// Attempt to read cross-tenant resources
|
||||
$collectionProject3WithProject1Key = $this->client->call(Client::METHOD_GET, '/databases/' . $database3['body']['$id'] . '/collections/' . $collection3['body']['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project1['body']['$id'],
|
||||
'x-appwrite-key' => $key1['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(404, $collectionProject3WithProject1Key['headers']['status-code']);
|
||||
|
||||
$collectionProject1WithProject3Key = $this->client->call(Client::METHOD_GET, '/databases/' . $database1['body']['$id'] . '/collections/' . $collection1['body']['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project3['body']['$id'],
|
||||
'x-appwrite-key' => $key3['body']['secret']
|
||||
]);
|
||||
|
||||
$this->assertEquals(404, $collectionProject1WithProject3Key['headers']['status-code']);
|
||||
|
||||
// Assert that shared project resources can have the same ID as they're unique on tenant + ID not just ID
|
||||
$collection5 = $this->client->call(Client::METHOD_POST, '/databases/' . $database2['body']['$id'] . '/collections', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $project2['body']['$id'],
|
||||
'x-appwrite-key' => $key2['body']['secret']
|
||||
], [
|
||||
'databaseId' => $database2['body']['$id'],
|
||||
'collectionId' => $collection4['body']['$id'],
|
||||
'name' => 'Amazing Collection',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $collection5['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,4 @@ class ProjectsCustomClientTest extends Scope
|
||||
{
|
||||
use ProjectCustom;
|
||||
use SideClient;
|
||||
|
||||
public function testMock()
|
||||
{
|
||||
$this->assertEquals(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,4 @@ class ProjectsCustomServerTest extends Scope
|
||||
{
|
||||
use ProjectCustom;
|
||||
use SideServer;
|
||||
|
||||
public function testMock()
|
||||
{
|
||||
$this->assertEquals(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user