Merge branch 'master' into feat-password-hash-algos

This commit is contained in:
Matej Bačo
2022-07-25 12:37:07 +00:00
908 changed files with 12166 additions and 5800 deletions
+31
View File
@@ -124,6 +124,37 @@ class EventTest extends TestCase
$this->assertContains('collections.*.documents.*', $event);
$this->assertContains('collections.*', $event);
$event = Event::generateEvents('databases.[databaseId].collections.[collectionId].documents.[documentId].create', [
'databaseId' => 'chaptersDB',
'collectionId' => 'chapters',
'documentId' => 'prolog',
]);
$this->assertCount(22, $event);
$this->assertContains('databases.chaptersDB.collections.chapters.documents.prolog.create', $event);
$this->assertContains('databases.chaptersDB.collections.chapters.documents.prolog', $event);
$this->assertContains('databases.chaptersDB.collections.chapters.documents.*.create', $event);
$this->assertContains('databases.chaptersDB.collections.chapters.documents.*', $event);
$this->assertContains('databases.chaptersDB.collections.chapters', $event);
$this->assertContains('databases.chaptersDB.collections.*.documents.prolog.create', $event);
$this->assertContains('databases.chaptersDB.collections.*.documents.prolog', $event);
$this->assertContains('databases.chaptersDB.collections.*', $event);
$this->assertContains('databases.chaptersDB', $event);
$this->assertContains('databases.*.collections.chapters.documents.prolog.create', $event);
$this->assertContains('databases.*.collections.chapters.documents.prolog', $event);
$this->assertContains('databases.*.collections.chapters', $event);
$this->assertContains('databases.*.collections.*.documents.*.create', $event);
$this->assertContains('databases.*.collections.*.documents.*', $event);
$this->assertContains('databases.*.collections.*', $event);
$this->assertContains('databases.*', $event);
$this->assertContains('databases.*.collections.*.documents.prolog', $event);
$this->assertContains('databases.*.collections.*.documents.prolog.create', $event);
$this->assertContains('databases.*.collections.chapters.documents.*', $event);
$this->assertContains('databases.*.collections.chapters.documents.*.create', $event);
$this->assertContains('databases.chaptersDB.collections.*.documents.*', $event);
$this->assertContains('databases.chaptersDB.collections.*.documents.*.create', $event);
try {
$event = Event::generateEvents('collections.[collectionId].documents.[documentId].create', [
'collectionId' => 'chapters'
@@ -31,15 +31,27 @@ class EventValidatorTest extends TestCase
$this->assertTrue($this->object->isValid('users.*.update.email'));
$this->assertTrue($this->object->isValid('users.*.update'));
$this->assertTrue($this->object->isValid('users.*'));
$this->assertTrue($this->object->isValid('collections.chapters.documents.prolog.create'));
$this->assertTrue($this->object->isValid('collections.chapters.documents.prolog'));
$this->assertTrue($this->object->isValid('collections.chapters.documents.*.create'));
$this->assertTrue($this->object->isValid('collections.chapters.documents.*'));
$this->assertTrue($this->object->isValid('collections.*.documents.prolog.create'));
$this->assertTrue($this->object->isValid('collections.*.documents.prolog'));
$this->assertTrue($this->object->isValid('collections.*.documents.*.create'));
$this->assertTrue($this->object->isValid('collections.*.documents.*'));
$this->assertTrue($this->object->isValid('collections.*'));
$this->assertTrue($this->object->isValid('databases.books.collections.chapters.documents.prolog.create'));
$this->assertTrue($this->object->isValid('databases.books.collections.chapters.documents.prolog'));
$this->assertTrue($this->object->isValid('databases.books.collections.chapters.documents.*.create'));
$this->assertTrue($this->object->isValid('databases.books.collections.chapters.documents.*'));
$this->assertTrue($this->object->isValid('databases.books.collections.*.documents.prolog.create'));
$this->assertTrue($this->object->isValid('databases.books.collections.*.documents.prolog'));
$this->assertTrue($this->object->isValid('databases.books.collections.*.documents.*.create'));
$this->assertTrue($this->object->isValid('databases.books.collections.*.documents.*'));
$this->assertTrue($this->object->isValid('databases.*.collections.chapters.documents.prolog.create'));
$this->assertTrue($this->object->isValid('databases.*.collections.chapters.documents.prolog'));
$this->assertTrue($this->object->isValid('databases.*.collections.chapters.documents.*.create'));
$this->assertTrue($this->object->isValid('databases.*.collections.chapters.documents.*'));
$this->assertTrue($this->object->isValid('databases.*.collections.*.documents.prolog.create'));
$this->assertTrue($this->object->isValid('databases.*.collections.*.documents.prolog'));
$this->assertTrue($this->object->isValid('databases.*.collections.*.documents.*.create'));
$this->assertTrue($this->object->isValid('databases.*.collections.*.documents.*'));
$this->assertTrue($this->object->isValid('databases.*.collections.*'));
$this->assertTrue($this->object->isValid('databases.*'));
$this->assertTrue($this->object->isValid('databases.books'));
$this->assertTrue($this->object->isValid('databases.books.collections.chapters'));
$this->assertTrue($this->object->isValid('databases.books.collections.*'));
$this->assertTrue($this->object->isValid('functions.*'));
$this->assertTrue($this->object->isValid('buckets.*'));
$this->assertTrue($this->object->isValid('teams.*'));
+8 -2
View File
@@ -202,7 +202,7 @@ class MessagingTest extends TestCase
* Test Collection Level Permissions
*/
$result = Realtime::fromPayload(
event: 'collections.collection_id.documents.document_id.create',
event: 'databases.database_id.collections.collection_id.documents.document_id.create',
payload: new Document([
'$id' => 'test',
'$collection' => 'collection',
@@ -214,6 +214,9 @@ class MessagingTest extends TestCase
'$read' => ['role:all'],
'$write' => ['role:all'],
'permission' => 'collection'
]),
database: new Document([
'$id' => 'database',
])
);
@@ -224,7 +227,7 @@ class MessagingTest extends TestCase
* Test Document Level Permissions
*/
$result = Realtime::fromPayload(
event: 'collections.collection_id.documents.document_id.create',
event: 'databases.database_id.collections.collection_id.documents.document_id.create',
payload: new Document([
'$id' => 'test',
'$collection' => 'collection',
@@ -236,6 +239,9 @@ class MessagingTest extends TestCase
'$read' => ['role:admin'],
'$write' => ['role:admin'],
'permission' => 'document'
]),
database: new Document([
'$id' => 'database',
])
);
-1
View File
@@ -4,7 +4,6 @@ namespace Appwrite\Tests;
use Appwrite\Migration\Migration;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
use Utopia\Database\Document;
-10
View File
@@ -38,14 +38,4 @@ class MigrationV13Test extends MigrationTest
$this->assertEquals($document->getAttribute('events'), ['users.*.create']);
}
public function testEventsConversion()
{
$migration = new V13();
$events = $migration->migrateEvents($migration->events);
foreach ($events as $event) {
$this->assertTrue((new Event())->isValid($event), $event);
}
$this->assertCount(44, $events);
}
}
+172
View File
@@ -0,0 +1,172 @@
<?php
namespace Appwrite\Tests;
use ReflectionClass;
use Appwrite\Migration\Version\V14;
use Utopia\Database\Document;
class MigrationV14Test extends MigrationTest
{
public function setUp(): void
{
$this->migration = new V14();
$reflector = new ReflectionClass('Appwrite\Migration\Version\V14');
$this->method = $reflector->getMethod('fixDocument');
$this->method->setAccessible(true);
}
public function testMigrateProjects()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'projects',
'version' => '0.14.0'
]));
$this->assertEquals($document->getAttribute('version'), '0.15.0');
$this->assertEquals($document->getAttribute('version'), '0.15.0');
}
public function testMigrateKeys()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'keys'
]));
$this->assertArrayHasKey('expire', $document->getArrayCopy());
$this->assertEquals($document->getAttribute('expire'), 0);
}
public function testMigrateWebhooks()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'webhooks'
]));
$this->assertArrayHasKey('signatureKey', $document->getArrayCopy());
$this->assertEquals(strlen($document->getAttribute('signatureKey')), 128);
}
public function testMigrateUsers()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'users',
'phoneVerification' => null
]));
$this->assertArrayHasKey('phoneVerification', $document->getArrayCopy());
$this->assertFalse($document->getAttribute('phoneVerification'));
}
public function testMigratePlatforms()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'platforms',
'$createdAt' => null,
'$updatedAt' => null,
'dateCreated' => 123456789,
'dateUpdated' => 987654321
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
$this->assertEquals($document->getUpdatedAt(), 987654321);
}
public function testMigrateFunctions()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'functions',
'$createdAt' => null,
'$updatedAt' => null,
'dateCreated' => 123456789,
'dateUpdated' => 987654321
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
$this->assertEquals($document->getUpdatedAt(), 987654321);
}
public function testMigrateDeployments()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'deployments',
'$createdAt' => null,
'dateCreated' => 123456789,
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
}
public function testMigrateExecutions()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'executions',
'$createdAt' => null,
'dateCreated' => 123456789,
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
}
public function testMigrateTeams()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'teams',
'$createdAt' => null,
'dateCreated' => 123456789,
]));
$this->assertEquals($document->getCreatedAt(), 123456789);
}
public function testMigrateAudits()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'audit',
'resource' => 'collection/movies',
'event' => 'collections.movies.create'
]));
$this->assertEquals($document->getAttribute('resource'), 'database/default/collection/movies');
$this->assertEquals($document->getAttribute('event'), 'databases.default.collections.movies.create');
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'audit',
'resource' => 'document/avatar',
'event' => 'collections.movies.documents.avatar.create'
]));
$this->assertEquals($document->getAttribute('resource'), 'database/default/collection/movies/document/avatar');
$this->assertEquals($document->getAttribute('event'), 'databases.default.collections.movies.documents.avatar.create');
}
public function testMigrateStats()
{
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'stats',
'metric' => 'database.collections.62b2039844d4277495d0.documents.create'
]));
$this->assertEquals($document->getAttribute('metric'), 'databases.default.collections.62b2039844d4277495d0.documents.create');
$document = $this->fixDocument(new Document([
'$id' => 'appwrite',
'$collection' => 'stats',
'metric' => 'users.create'
]));
$this->assertEquals($document->getAttribute('metric'), 'users.create');
}
}