1
0
Fork 0
mirror of synced 2024-06-01 18:39:57 +12:00
This commit is contained in:
Jake Barnby 2022-08-13 02:41:57 +12:00
parent d2b9102f84
commit 09b001e891
15 changed files with 63 additions and 63 deletions

View file

@ -142,7 +142,7 @@ Learn more at our [Technology Stack](#technology-stack) section.
##### Security
- [Appwrite Auth and ACL](https://github.com/appwrite/appwrite/blob/0.7.x/docs/specs/authentication.drawio.svg)
- [Appwrite Auth and ACL](https://github.com/appwrite/appwrite/blob/0.16.x/docs/specs/authentication.drawio.svg)
- [OAuth](https://en.wikipedia.org/wiki/OAuth)
- [Encryption](https://medium.com/searchencrypt/what-is-encryption-how-does-it-work-e8f20e340537#:~:text=Encryption%20is%20a%20process%20that,%2C%20or%20decrypt%2C%20the%20information.)
- [Hashing](https://searchsqlserver.techtarget.com/definition/hashing#:~:text=Hashing%20is%20the%20transformation%20of,it%20using%20the%20original%20value.)

View file

@ -555,9 +555,9 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
$session = $dbForProject->createDocument('sessions', $session->setAttribute('$permissions', [
"read(user:{$user->getId()})",
"create(user:{$user->getId()})",
"update(user:{$user->getId()})",
"delete(user:{$user->getId()})",
"create(user:{$user->getId()})",
"update(user:{$user->getId()})",
"delete(user:{$user->getId()})",
]));
$dbForProject->deleteCachedDocument('users', $user->getId());
@ -698,9 +698,9 @@ App::post('/v1/account/sessions/magic-url')
$token = $dbForProject->createDocument('tokens', $token
->setAttribute('$permissions', [
"read(user:{$user->getId()})",
"create(user:{$user->getId()})",
"update(user:{$user->getId()})",
"delete(user:{$user->getId()})",
"create(user:{$user->getId()})",
"update(user:{$user->getId()})",
"delete(user:{$user->getId()})",
]));
$dbForProject->deleteCachedDocument('users', $user->getId());

View file

@ -75,9 +75,12 @@ App::post('/v1/teams')
$membership = new Document([
'$id' => $membershipId,
'$permissions' => [
"read(user:{$user->getId()}, team:{$team->getId()})",
"update(user:{$user->getId()}, team:{$team->getId()}/owner)",
"delete(user:{$user->getId()}, team:{$team->getId()}/owner)",
"read(user:{$user->getId()})",
"read(team:{$team->getId()})",
"update(user:{$user->getId()})",
"update(team:{$team->getId()}/owner)",
"delete(user:{$user->getId()})",
"delete(team:{$team->getId()}/owner)",
],
'userId' => $user->getId(),
'userInternalId' => $user->getInternalId(),

16
composer.lock generated
View file

@ -1737,12 +1737,12 @@
"source": {
"type": "git",
"url": "https://github.com/utopia-php/abuse.git",
"reference": "57b5454b37bba9ebf36fc7cbba49786e92a3a577"
"reference": "438925eddc8975b8377d1b0fced74055935870ce"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/57b5454b37bba9ebf36fc7cbba49786e92a3a577",
"reference": "57b5454b37bba9ebf36fc7cbba49786e92a3a577",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/438925eddc8975b8377d1b0fced74055935870ce",
"reference": "438925eddc8975b8377d1b0fced74055935870ce",
"shasum": ""
},
"require": {
@ -1782,7 +1782,7 @@
"issues": "https://github.com/utopia-php/abuse/issues",
"source": "https://github.com/utopia-php/abuse/tree/refactor-permissions"
},
"time": "2022-08-10T04:50:31+00:00"
"time": "2022-08-12T13:21:57+00:00"
},
{
"name": "utopia-php/analytics",
@ -2055,12 +2055,12 @@
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
"reference": "4b3e11b0048723cff345de0b2196b5d85b0d072e"
"reference": "4af6d9d1e9ec518e5f87628051132a6402c647fc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/4b3e11b0048723cff345de0b2196b5d85b0d072e",
"reference": "4b3e11b0048723cff345de0b2196b5d85b0d072e",
"url": "https://api.github.com/repos/utopia-php/database/zipball/4af6d9d1e9ec518e5f87628051132a6402c647fc",
"reference": "4af6d9d1e9ec518e5f87628051132a6402c647fc",
"shasum": ""
},
"require": {
@ -2111,7 +2111,7 @@
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/refactor-permissions"
},
"time": "2022-08-12T12:06:57+00:00"
"time": "2022-08-12T13:00:50+00:00"
},
{
"name": "utopia-php/domains",

View file

@ -186,7 +186,7 @@ class Realtime extends Adapter
*/
if (
\array_key_exists($channel, $this->subscriptions[$event['project']][$role])
&& (\in_array($role, $event['roles']) || \in_array('role:all', $event['roles']))
&& (\in_array($role, $event['roles']) || \in_array('any', $event['roles']))
) {
/**
* Saving all connections that are allowed to receive this event.

View file

@ -15,8 +15,7 @@ class PermissionsProcessor
return null;
}
$aggregates = [
'admin' => ['create', 'update', 'delete', 'read',],
'write' => ['create', 'update', 'delete',],
'admin' => Database::PERMISSIONS,
];
foreach ($permissions as $i => $permission) {
foreach ($aggregates as $type => $subTypes) {
@ -48,7 +47,7 @@ class PermissionsProcessor
return $permissions;
}
foreach (Database::PERMISSIONS as $permission) {
// Default any missing permisions to the current user
// Default any missing permissions to the current user
if (empty(\preg_grep("#^{$permission}\(.+\)$#", $permissions)) && !empty($userId)) {
$permissions[] = $permission . '(user:' . $userId . ')';
}
@ -67,11 +66,9 @@ class PermissionsProcessor
if (!\str_starts_with($permission, $type)) {
continue;
}
$matches = \explode(',', \str_replace([$type, '(', ')', ' '], '', $permission));
foreach ($matches as $role) {
if (!Authorization::isRole($role)) {
return false;
}
$role = \str_replace([$type, '(', ')', ' '], '', $permission);
if (!Authorization::isRole($role)) {
return false;
}
}
}

View file

@ -47,8 +47,8 @@ class FunctionsCustomServerTest extends Scope
$this->assertNotEmpty($response1['body']['$id']);
$this->assertEquals('Test', $response1['body']['name']);
$this->assertEquals('php-8.0', $response1['body']['runtime']);
$this->assertIsString($response1['body']['$createdAt']);
$this->assertIsString($response1['body']['$updatedAt']);
$this->assertIsInt($response1['body']['$createdAt']);
$this->assertIsInt($response1['body']['$updatedAt']);
$this->assertEquals('', $response1['body']['deployment']);
$this->assertEquals([
'funcKey1' => 'funcValue1',
@ -248,8 +248,8 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(200, $response1['headers']['status-code']);
$this->assertNotEmpty($response1['body']['$id']);
$this->assertEquals('Test1', $response1['body']['name']);
$this->assertIsString($response1['body']['$createdAt']);
$this->assertIsString($response1['body']['$updatedAt']);
$this->assertIsInt($response1['body']['$createdAt']);
$this->assertIsInt($response1['body']['$updatedAt']);
$this->assertEquals('', $response1['body']['deployment']);
$this->assertEquals([
'key4' => 'value4',
@ -294,7 +294,7 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(202, $deployment['headers']['status-code']);
$this->assertNotEmpty($deployment['body']['$id']);
$this->assertIsString($deployment['body']['$createdAt']);
$this->assertIsInt($deployment['body']['$createdAt']);
$this->assertEquals('index.php', $deployment['body']['entrypoint']);
// Wait for deployment to build.
@ -343,7 +343,7 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(202, $largeTag['headers']['status-code']);
$this->assertNotEmpty($largeTag['body']['$id']);
$this->assertIsString($largeTag['body']['$createdAt']);
$this->assertIsInt($largeTag['body']['$createdAt']);
$this->assertEquals('index.php', $largeTag['body']['entrypoint']);
$this->assertGreaterThan(10000, $largeTag['body']['size']);
@ -365,8 +365,8 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertIsString($response['body']['$createdAt']);
$this->assertIsString($response['body']['$updatedAt']);
$this->assertIsInt($response['body']['$createdAt']);
$this->assertIsInt($response['body']['$updatedAt']);
$this->assertEquals($data['deploymentId'], $response['body']['deployment']);
/**
@ -487,7 +487,7 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(202, $execution['headers']['status-code']);
$this->assertNotEmpty($execution['body']['$id']);
$this->assertNotEmpty($execution['body']['functionId']);
$this->assertIsString($execution['body']['$createdAt']);
$this->assertIsInt($execution['body']['$createdAt']);
$this->assertEquals($data['functionId'], $execution['body']['functionId']);
$this->assertEquals('waiting', $execution['body']['status']);
$this->assertEquals(0, $execution['body']['statusCode']);
@ -504,7 +504,7 @@ class FunctionsCustomServerTest extends Scope
$this->assertNotEmpty($execution['body']['$id']);
$this->assertNotEmpty($execution['body']['functionId']);
$this->assertIsString($execution['body']['$createdAt']);
$this->assertIsInt($execution['body']['$createdAt']);
$this->assertEquals($data['functionId'], $execution['body']['functionId']);
$this->assertEquals('completed', $execution['body']['status']);
$this->assertEquals(200, $execution['body']['statusCode']);

View file

@ -49,7 +49,7 @@ trait StorageBase
]);
$this->assertEquals(201, $file['headers']['status-code']);
$this->assertNotEmpty($file['body']['$id']);
$this->assertIsString($file['body']['$createdAt']);
$this->assertIsInt($file['body']['$createdAt']);
$this->assertEquals('logo.png', $file['body']['name']);
$this->assertEquals('image/png', $file['body']['mimeType']);
$this->assertEquals(47218, $file['body']['sizeOriginal']);
@ -118,7 +118,7 @@ trait StorageBase
$this->assertEquals(201, $largeFile['headers']['status-code']);
$this->assertNotEmpty($largeFile['body']['$id']);
$this->assertIsString($largeFile['body']['$createdAt']);
$this->assertIsInt($largeFile['body']['$createdAt']);
$this->assertEquals('large-file.mp4', $largeFile['body']['name']);
$this->assertEquals('video/mp4', $largeFile['body']['mimeType']);
$this->assertEquals($totalSize, $largeFile['body']['sizeOriginal']);
@ -290,7 +290,7 @@ trait StorageBase
$this->assertEquals(200, $file1['headers']['status-code']);
$this->assertNotEmpty($file1['body']['$id']);
$this->assertIsString($file1['body']['$createdAt']);
$this->assertIsInt($file1['body']['$createdAt']);
$this->assertEquals('logo.png', $file1['body']['name']);
$this->assertEquals('image/png', $file1['body']['mimeType']);
$this->assertEquals(47218, $file1['body']['sizeOriginal']);
@ -588,7 +588,7 @@ trait StorageBase
$this->assertEquals(200, $file['headers']['status-code']);
$this->assertNotEmpty($file['body']['$id']);
$this->assertIsString($file['body']['$createdAt']);
$this->assertIsInt($file['body']['$createdAt']);
$this->assertEquals('logo.png', $file['body']['name']);
$this->assertEquals('image/png', $file['body']['mimeType']);
$this->assertEquals(47218, $file['body']['sizeOriginal']);

View file

@ -52,7 +52,7 @@ class StorageCustomClientTest extends Scope
$fileId = $file['body']['$id'];
$this->assertEquals($file['headers']['status-code'], 201);
$this->assertNotEmpty($fileId);
$this->assertIsString($file['body']['$createdAt']);
$this->assertIsInt($file['body']['$createdAt']);
$this->assertEquals('permissions.png', $file['body']['name']);
$this->assertEquals('image/png', $file['body']['mimeType']);
$this->assertEquals(47218, $file['body']['sizeOriginal']);
@ -146,7 +146,7 @@ class StorageCustomClientTest extends Scope
$this->assertContains('read(user:' . $this->getUser()['$id'] . ')', $file['body']['$permissions']);
$this->assertContains('update(user:' . $this->getUser()['$id'] . ')', $file['body']['$permissions']);
$this->assertContains('delete(user:' . $this->getUser()['$id'] . ')', $file['body']['$permissions']);
$this->assertIsString($file['body']['$createdAt']);
$this->assertIsInt($file['body']['$createdAt']);
$this->assertEquals('permissions.png', $file['body']['name']);
$this->assertEquals('image/png', $file['body']['mimeType']);
$this->assertEquals(47218, $file['body']['sizeOriginal']);

View file

@ -28,7 +28,7 @@ class StorageCustomServerTest extends Scope
]);
$this->assertEquals(201, $bucket['headers']['status-code']);
$this->assertNotEmpty($bucket['body']['$id']);
$this->assertIsString($bucket['body']['$createdAt']);
$this->assertIsInt($bucket['body']['$createdAt']);
$this->assertIsArray($bucket['body']['$permissions']);
$this->assertIsArray($bucket['body']['allowedFileExtensions']);
$this->assertEquals('Test Bucket', $bucket['body']['name']);
@ -186,7 +186,7 @@ class StorageCustomServerTest extends Scope
]);
$this->assertEquals(200, $bucket['headers']['status-code']);
$this->assertNotEmpty($bucket['body']['$id']);
$this->assertIsString($bucket['body']['$createdAt']);
$this->assertIsInt($bucket['body']['$createdAt']);
$this->assertIsArray($bucket['body']['$permissions']);
$this->assertIsArray($bucket['body']['allowedFileExtensions']);

View file

@ -25,7 +25,7 @@ trait TeamsBase
$this->assertEquals('Arsenal', $response1['body']['name']);
$this->assertGreaterThan(-1, $response1['body']['total']);
$this->assertIsInt($response1['body']['total']);
$this->assertIsString($response1['body']['$createdAt']);
$this->assertIsInt($response1['body']['$createdAt']);
$teamUid = $response1['body']['$id'];
$teamName = $response1['body']['name'];
@ -45,7 +45,7 @@ trait TeamsBase
$this->assertEquals('Manchester United', $response2['body']['name']);
$this->assertGreaterThan(-1, $response2['body']['total']);
$this->assertIsInt($response2['body']['total']);
$this->assertIsString($response2['body']['$createdAt']);
$this->assertIsInt($response2['body']['$createdAt']);
$response3 = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
'content-type' => 'application/json',
@ -60,7 +60,7 @@ trait TeamsBase
$this->assertEquals('Newcastle', $response3['body']['name']);
$this->assertGreaterThan(-1, $response3['body']['total']);
$this->assertIsInt($response3['body']['total']);
$this->assertIsString($response3['body']['$createdAt']);
$this->assertIsInt($response3['body']['$createdAt']);
/**
* Test for FAILURE
@ -96,7 +96,7 @@ trait TeamsBase
$this->assertEquals('Arsenal', $response['body']['name']);
$this->assertGreaterThan(-1, $response['body']['total']);
$this->assertIsInt($response['body']['total']);
$this->assertIsString($response['body']['$createdAt']);
$this->assertIsInt($response['body']['$createdAt']);
/**
* Test for FAILURE
@ -260,7 +260,7 @@ trait TeamsBase
$this->assertEquals('Demo', $response['body']['name']);
$this->assertGreaterThan(-1, $response['body']['total']);
$this->assertIsInt($response['body']['total']);
$this->assertIsString($response['body']['$createdAt']);
$this->assertIsInt($response['body']['$createdAt']);
$response = $this->client->call(Client::METHOD_PUT, '/teams/' . $response['body']['$id'], array_merge([
'content-type' => 'application/json',
@ -275,7 +275,7 @@ trait TeamsBase
$this->assertEquals('Demo New', $response['body']['name']);
$this->assertGreaterThan(-1, $response['body']['total']);
$this->assertIsInt($response['body']['total']);
$this->assertIsString($response['body']['$createdAt']);
$this->assertIsInt($response['body']['$createdAt']);
/**
* Test for FAILURE
@ -311,7 +311,7 @@ trait TeamsBase
$this->assertEquals('Demo', $response['body']['name']);
$this->assertGreaterThan(-1, $response['body']['total']);
$this->assertIsInt($response['body']['total']);
$this->assertIsString($response['body']['$createdAt']);
$this->assertIsInt($response['body']['$createdAt']);
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid, array_merge([
'content-type' => 'application/json',

View file

@ -204,7 +204,7 @@ trait TeamsBaseServer
$this->assertEquals('Arsenal', $response['body']['name']);
$this->assertEquals(1, $response['body']['total']);
$this->assertIsInt($response['body']['total']);
$this->assertIsString($response['body']['$createdAt']);
$this->assertIsInt($response['body']['$createdAt']);
/** Delete User */
@ -230,6 +230,6 @@ trait TeamsBaseServer
$this->assertEquals('Arsenal', $response['body']['name']);
$this->assertEquals(0, $response['body']['total']);
$this->assertIsInt($response['body']['total']);
$this->assertIsString($response['body']['$createdAt']);
$this->assertIsInt($response['body']['$createdAt']);
}
}

View file

@ -527,7 +527,7 @@ trait WebhooksBase
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertIsArray($webhook['data']['$permissions']);
$this->assertEquals($webhook['data']['name'], 'logo.png');
$this->assertIsString($webhook['data']['$createdAt']);
$this->assertIsInt($webhook['data']['$createdAt']);
$this->assertNotEmpty($webhook['data']['signature']);
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
@ -586,7 +586,7 @@ trait WebhooksBase
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertIsArray($webhook['data']['$permissions']);
$this->assertEquals($webhook['data']['name'], 'logo.png');
$this->assertIsString($webhook['data']['$createdAt']);
$this->assertIsInt($webhook['data']['$createdAt']);
$this->assertNotEmpty($webhook['data']['signature']);
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
@ -636,7 +636,7 @@ trait WebhooksBase
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertIsArray($webhook['data']['$permissions']);
$this->assertEquals($webhook['data']['name'], 'logo.png');
$this->assertIsString($webhook['data']['$createdAt']);
$this->assertIsInt($webhook['data']['$createdAt']);
$this->assertNotEmpty($webhook['data']['signature']);
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
@ -718,7 +718,7 @@ trait WebhooksBase
$this->assertEquals('Arsenal', $webhook['data']['name']);
$this->assertGreaterThan(-1, $webhook['data']['total']);
$this->assertIsInt($webhook['data']['total']);
$this->assertIsString($webhook['data']['$createdAt']);
$this->assertIsInt($webhook['data']['$createdAt']);
/**
* Test for FAILURE
@ -763,7 +763,7 @@ trait WebhooksBase
$this->assertEquals('Demo New', $webhook['data']['name']);
$this->assertGreaterThan(-1, $webhook['data']['total']);
$this->assertIsInt($webhook['data']['total']);
$this->assertIsString($webhook['data']['$createdAt']);
$this->assertIsInt($webhook['data']['$createdAt']);
/**
* Test for FAILURE
@ -812,7 +812,7 @@ trait WebhooksBase
$this->assertEquals('Chelsea', $webhook['data']['name']);
$this->assertGreaterThan(-1, $webhook['data']['total']);
$this->assertIsInt($webhook['data']['total']);
$this->assertIsString($webhook['data']['$createdAt']);
$this->assertIsInt($webhook['data']['$createdAt']);
/**
* Test for FAILURE

View file

@ -153,7 +153,7 @@ class MessagingChannelsTest extends TestCase
foreach ($this->allChannels as $index => $channel) {
$event = [
'project' => '1',
'roles' => ['role:all'],
'roles' => ['any'],
'data' => [
'channels' => [
0 => $channel,

View file

@ -20,7 +20,7 @@ class MessagingGuestTest extends TestCase
$event = [
'project' => '1',
'roles' => ['role:all'],
'roles' => ['any'],
'data' => [
'channels' => [
0 => 'documents',
@ -95,7 +95,7 @@ class MessagingGuestTest extends TestCase
$this->assertEmpty($receivers);
$event['roles'] = ['role:all'];
$event['roles'] = ['any'];
$event['data']['channels'] = ['documents.123'];
$receivers = $realtime->getSubscribers($event);