Merge branch '0.16.x' of https://github.com/appwrite/appwrite into matej-qa-3

This commit is contained in:
Christy Jacob
2022-09-13 18:21:44 +00:00
35 changed files with 639 additions and 285 deletions
+131 -10
View File
@@ -26,8 +26,7 @@ class UsageTest extends Scope
parent::setUp();
}
#[Retry(count: 1)]
public function testUsersStats(): array
public function testPrepareUsersStats(): array
{
$project = $this->getProject(true);
$projectId = $project['$id'];
@@ -63,8 +62,27 @@ class UsageTest extends Scope
}
}
return [
'projectId' => $projectId,
'headers' => $headers,
'usersCount' => $usersCount,
'requestsCount' => $requestsCount
];
}
/**
* @depends testPrepareUsersStats
*/
#[Retry(count: 1)]
public function testUsersStats(array $data): array
{
sleep(35);
$projectId = $data['projectId'];
$headers = $data['headers'];
$usersCount = $data['usersCount'];
$requestsCount = $data['requestsCount'];
// console request
$cheaders = [
'origin' => 'http://localhost',
@@ -94,8 +112,7 @@ class UsageTest extends Scope
}
/** @depends testUsersStats */
#[Retry(count: 1)]
public function testStorageStats(array $data): array
public function testPrepareStorageStats(array $data): array
{
$projectId = $data['projectId'];
$headers = $data['headers'];
@@ -190,6 +207,40 @@ class UsageTest extends Scope
}
}
return array_merge($data, [
'bucketId' => $bucketId,
'bucketsCount' => $bucketsCount,
'requestsCount' => $requestsCount,
'storageTotal' => $storageTotal,
'bucketsCreate' => $bucketsCreate,
'bucketsDelete' => $bucketsDelete,
'bucketsRead' => $bucketsRead,
'filesCount' => $filesCount,
'filesRead' => $filesRead,
'filesCreate' => $filesCreate,
'filesDelete' => $filesDelete,
]);
}
/**
* @depends testPrepareStorageStats
*/
#[Retry(count: 1)]
public function testStorageStats(array $data): array
{
$projectId = $data['projectId'];
$bucketId = $data['bucketId'];
$bucketsCount = $data['bucketsCount'];
$requestsCount = $data['requestsCount'];
$storageTotal = $data['storageTotal'];
$bucketsCreate = $data['bucketsCreate'];
$bucketsDelete = $data['bucketsDelete'];
$bucketsRead = $data['bucketsRead'];
$filesCount = $data['filesCount'];
$filesRead = $data['filesRead'];
$filesCreate = $data['filesCreate'];
$filesDelete = $data['filesDelete'];
sleep(35);
// console request
@@ -239,8 +290,7 @@ class UsageTest extends Scope
}
/** @depends testStorageStats */
#[Retry(count: 1)]
public function testDatabaseStats(array $data): array
public function testPrepareDatabaseStats(array $data): array
{
$headers = $data['headers'];
$projectId = $data['projectId'];
@@ -366,6 +416,58 @@ class UsageTest extends Scope
}
}
$data = array_merge($data, [
'databaseId' => $databaseId,
'collectionId' => $collectionId,
'requestsCount' => $requestsCount,
'databasesCount' => $databasesCount,
'databasesCreate' => $databasesCreate,
'databasesRead' => $databasesRead,
'databasesDelete' => $databasesDelete,
'collectionsCount' => $collectionsCount,
'collectionsCreate' => $collectionsCreate,
'collectionsRead' => $collectionsRead,
'collectionsUpdate' => $collectionsUpdate,
'collectionsDelete' => $collectionsDelete,
'documentsCount' => $documentsCount,
'documentsCreate' => $documentsCreate,
'documentsRead' => $documentsRead,
'documentsDelete' => $documentsDelete,
]);
return $data;
}
/** @depends testPrepareDatabaseStats */
#[Retry(count: 1)]
public function testDatabaseStats(array $data): array
{
$headers = $data['headers'];
$projectId = $data['projectId'];
$databaseId = $data['databaseId'];
$collectionId = $data['collectionId'];
$requestsCount = $data['requestsCount'];
$databasesCount = $data['databasesCount'];
$databasesCreate = $data['databasesCreate'];
$databasesRead = $data['databasesRead'];
$databasesDelete = $data['databasesDelete'];
$collectionsCount = $data['collectionsCount'];
$collectionsCreate = $data['collectionsCreate'];
$collectionsRead = $data['collectionsRead'];
$collectionsUpdate = $data['collectionsUpdate'];
$collectionsDelete = $data['collectionsDelete'];
$documentsCount = $data['documentsCount'];
$documentsCreate = $data['documentsCreate'];
$documentsRead = $data['documentsRead'];
$documentsDelete = $data['documentsDelete'];
sleep(35);
// check datbase stats
@@ -440,8 +542,7 @@ class UsageTest extends Scope
/** @depends testDatabaseStats */
#[Retry(count: 1)]
public function testFunctionsStats(array $data): void
public function testPrepareFunctionsStats(array $data): array
{
$headers = $data['headers'];
$functionId = '';
@@ -505,7 +606,7 @@ class UsageTest extends Scope
$this->assertEquals(201, $execution['headers']['status-code']);
$this->assertNotEmpty($execution['body']['$id']);
$this->assertEquals($functionId, $execution['body']['functionId']);
$executionTime += (int) ($execution['body']['time'] * 1000);
$executionTime += (int) ($execution['body']['duration'] * 1000);
if ($execution['body']['status'] == 'failed') {
$failures++;
} elseif ($execution['body']['status'] == 'completed') {
@@ -524,7 +625,27 @@ class UsageTest extends Scope
} elseif ($execution['body']['status'] == 'completed') {
$executions++;
}
$executionTime += (int) ($execution['body']['time'] * 1000);
$executionTime += (int) ($execution['body']['duration'] * 1000);
$data = array_merge($data, [
'functionId' => $functionId,
'executionTime' => $executionTime,
'executions' => $executions,
'failures' => $failures,
]);
return $data;
}
/** @depends testPrepareFunctionsStats */
#[Retry(count: 1)]
public function testFunctionsStats(array $data): void
{
$headers = $data['headers'];
$functionId = $data['functionId'];
$executionTime = $data['executionTime'];
$executions = $data['executions'];
$failures = $data['failures'];
sleep(25);
@@ -608,7 +608,7 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(0, $execution['body']['statusCode']);
$this->assertEquals('', $execution['body']['response']);
$this->assertEquals('', $execution['body']['stderr']);
$this->assertEquals(0, $execution['body']['time']);
$this->assertEquals(0, $execution['body']['duration']);
sleep(5);
@@ -631,7 +631,7 @@ class FunctionsCustomServerTest extends Scope
$this->assertStringContainsString('8.0', $execution['body']['response']);
$this->assertStringContainsString('êä', $execution['body']['response']); // tests unknown utf-8 chars
$this->assertEquals('', $execution['body']['stderr']);
$this->assertLessThan(0.500, $execution['body']['time']);
$this->assertLessThan(0.500, $execution['body']['duration']);
/**
* Test for FAILURE
@@ -750,7 +750,7 @@ class FunctionsCustomServerTest extends Scope
$this->assertStringContainsString('PHP', $execution['body']['response']);
$this->assertStringContainsString('8.0', $execution['body']['response']);
$this->assertStringContainsString('êä', $execution['body']['response']); // tests unknown utf-8 chars
$this->assertLessThan(0.500, $execution['body']['time']);
$this->assertLessThan(0.500, $execution['body']['duration']);
return $data;
}
@@ -909,9 +909,9 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
$this->assertEquals($executions['body']['executions'][0]['status'], 'failed');
$this->assertEquals($executions['body']['executions'][0]['statusCode'], 500);
$this->assertGreaterThan(2, $executions['body']['executions'][0]['time']);
$this->assertLessThan(6, $executions['body']['executions'][0]['time']);
$this->assertGreaterThan(4, $executions['body']['executions'][0]['time']);
$this->assertGreaterThan(2, $executions['body']['executions'][0]['duration']);
$this->assertLessThan(6, $executions['body']['executions'][0]['duration']);
$this->assertGreaterThan(4, $executions['body']['executions'][0]['duration']);
$this->assertEquals($executions['body']['executions'][0]['response'], '');
$this->assertEquals($executions['body']['executions'][0]['stderr'], 'An internal curl error has occurred within the executor! Error Msg: Operation timed out');
+14 -14
View File
@@ -2,7 +2,7 @@
'req' variable has:
'headers' - object with request headers
'payload' - object with request body data
'env' - object with environment variables
'variables' - object with function variables
'res' variable has:
'send(text, status)' - function to return text response. Status code defaults to 200
'json(obj, status)' - function to return JSON response. Status code defaults to 200
@@ -12,18 +12,18 @@
Future<void> start(final request, final response) async {
response.json({
'APPWRITE_FUNCTION_ID' : request.env['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' : request.env['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' : request.env['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' : request.env['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' : request.env['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' : request.env['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' : request.env['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' : request.env['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_DATA' : request.env['APPWRITE_FUNCTION_DATA'],
'APPWRITE_FUNCTION_USER_ID' : request.env['APPWRITE_FUNCTION_USER_ID'],
'APPWRITE_FUNCTION_JWT' : request.env['APPWRITE_FUNCTION_JWT'],
'APPWRITE_FUNCTION_PROJECT_ID' : request.env['APPWRITE_FUNCTION_PROJECT_ID'],
'CUSTOM_VARIABLE' : request.env['CUSTOM_VARIABLE']
'APPWRITE_FUNCTION_ID' : request.variables['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' : request.variables['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' : request.variables['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' : request.variables['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' : request.variables['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' : request.variables['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' : request.variables['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' : request.variables['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_DATA' : request.variables['APPWRITE_FUNCTION_DATA'],
'APPWRITE_FUNCTION_USER_ID' : request.variables['APPWRITE_FUNCTION_USER_ID'],
'APPWRITE_FUNCTION_JWT' : request.variables['APPWRITE_FUNCTION_JWT'],
'APPWRITE_FUNCTION_PROJECT_ID' : request.variables['APPWRITE_FUNCTION_PROJECT_ID'],
'CUSTOM_VARIABLE' : request.variables['CUSTOM_VARIABLE']
});
}
+14 -14
View File
@@ -2,7 +2,7 @@
'req' variable has:
'headers' - object with request headers
'payload' - object with request body data
'env' - object with environment variables
'variables' - object with function variables
'res' variable has:
'send(text, status)' - function to return text response. Status code defaults to 200
'json(obj, status)' - function to return JSON response. Status code defaults to 200
@@ -12,18 +12,18 @@
module.exports = async(req, res) => {
res.json({
'APPWRITE_FUNCTION_ID' : req.env.APPWRITE_FUNCTION_ID,
'APPWRITE_FUNCTION_NAME' : req.env.APPWRITE_FUNCTION_NAME,
'APPWRITE_FUNCTION_DEPLOYMENT' : req.env.APPWRITE_FUNCTION_DEPLOYMENT,
'APPWRITE_FUNCTION_TRIGGER' : req.env.APPWRITE_FUNCTION_TRIGGER,
'APPWRITE_FUNCTION_RUNTIME_NAME' : req.env.APPWRITE_FUNCTION_RUNTIME_NAME,
'APPWRITE_FUNCTION_RUNTIME_VERSION' : req.env.APPWRITE_FUNCTION_RUNTIME_VERSION,
'APPWRITE_FUNCTION_EVENT' : req.env.APPWRITE_FUNCTION_EVENT,
'APPWRITE_FUNCTION_EVENT_DATA' : req.env.APPWRITE_FUNCTION_EVENT_DATA,
'APPWRITE_FUNCTION_DATA' : req.env.APPWRITE_FUNCTION_DATA,
'APPWRITE_FUNCTION_USER_ID' : req.env.APPWRITE_FUNCTION_USER_ID,
'APPWRITE_FUNCTION_JWT' : req.env.APPWRITE_FUNCTION_JWT,
'APPWRITE_FUNCTION_PROJECT_ID' : req.env.APPWRITE_FUNCTION_PROJECT_ID,
'CUSTOM_VARIABLE' : req.env.CUSTOM_VARIABLE
'APPWRITE_FUNCTION_ID' : req.variables.APPWRITE_FUNCTION_ID,
'APPWRITE_FUNCTION_NAME' : req.variables.APPWRITE_FUNCTION_NAME,
'APPWRITE_FUNCTION_DEPLOYMENT' : req.variables.APPWRITE_FUNCTION_DEPLOYMENT,
'APPWRITE_FUNCTION_TRIGGER' : req.variables.APPWRITE_FUNCTION_TRIGGER,
'APPWRITE_FUNCTION_RUNTIME_NAME' : req.variables.APPWRITE_FUNCTION_RUNTIME_NAME,
'APPWRITE_FUNCTION_RUNTIME_VERSION' : req.variables.APPWRITE_FUNCTION_RUNTIME_VERSION,
'APPWRITE_FUNCTION_EVENT' : req.variables.APPWRITE_FUNCTION_EVENT,
'APPWRITE_FUNCTION_EVENT_DATA' : req.variables.APPWRITE_FUNCTION_EVENT_DATA,
'APPWRITE_FUNCTION_DATA' : req.variables.APPWRITE_FUNCTION_DATA,
'APPWRITE_FUNCTION_USER_ID' : req.variables.APPWRITE_FUNCTION_USER_ID,
'APPWRITE_FUNCTION_JWT' : req.variables.APPWRITE_FUNCTION_JWT,
'APPWRITE_FUNCTION_PROJECT_ID' : req.variables.APPWRITE_FUNCTION_PROJECT_ID,
'CUSTOM_VARIABLE' : req.variables.CUSTOM_VARIABLE
});
}
+12 -12
View File
@@ -4,17 +4,17 @@ return function ($request, $response) {
\var_dump("Amazing Function Log"); // We test logs (stdout) visibility with this
$response->json([
'APPWRITE_FUNCTION_ID' => $request['env']['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' => $request['env']['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' => $request['env']['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' => $request['env']['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' => $request['env']['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $request['env']['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' => $request['env']['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' => $request['env']['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_DATA' => $request['env']['APPWRITE_FUNCTION_DATA'],
'APPWRITE_FUNCTION_USER_ID' => $request['env']['APPWRITE_FUNCTION_USER_ID'],
'APPWRITE_FUNCTION_JWT' => $request['env']['APPWRITE_FUNCTION_JWT'],
'APPWRITE_FUNCTION_PROJECT_ID' => $request['env']['APPWRITE_FUNCTION_PROJECT_ID'],
'APPWRITE_FUNCTION_ID' => $request['variables']['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' => $request['variables']['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' => $request['variables']['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' => $request['variables']['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' => $request['variables']['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $request['variables']['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' => $request['variables']['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' => $request['variables']['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_DATA' => $request['variables']['APPWRITE_FUNCTION_DATA'],
'APPWRITE_FUNCTION_USER_ID' => $request['variables']['APPWRITE_FUNCTION_USER_ID'],
'APPWRITE_FUNCTION_JWT' => $request['variables']['APPWRITE_FUNCTION_JWT'],
'APPWRITE_FUNCTION_PROJECT_ID' => $request['variables']['APPWRITE_FUNCTION_PROJECT_ID'],
]);
};
@@ -2,14 +2,14 @@
return function ($request, $response) {
return $response->json([
'APPWRITE_FUNCTION_ID' => $request['env']['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' => $request['env']['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' => $request['env']['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' => $request['env']['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' => $request['env']['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $request['env']['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' => $request['env']['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' => $request['env']['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_ID' => $request['variables']['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' => $request['variables']['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' => $request['variables']['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' => $request['variables']['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' => $request['variables']['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $request['variables']['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' => $request['variables']['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' => $request['variables']['APPWRITE_FUNCTION_EVENT_DATA'],
'UNICODE_TEST' => "êä"
]);
};
+8 -8
View File
@@ -2,14 +2,14 @@
return function ($request, $response) {
return $response->json([
'APPWRITE_FUNCTION_ID' => $request['env']['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' => $request['env']['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' => $request['env']['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' => $request['env']['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' => $request['env']['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $request['env']['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' => $request['env']['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' => $request['env']['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_ID' => $request['variables']['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' => $request['variables']['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' => $request['variables']['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' => $request['variables']['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' => $request['variables']['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $request['variables']['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' => $request['variables']['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' => $request['variables']['APPWRITE_FUNCTION_EVENT_DATA'],
'UNICODE_TEST' => "êä"
]);
};
+14 -14
View File
@@ -3,7 +3,7 @@ import json
# 'req' variable has:
# 'headers' - object with request headers
# 'payload' - object with request body data
# 'env' - object with environment variables
# 'variables' - object with function variables
# 'res' variable has:
# 'send(text, status)' - function to return text response. Status code defaults to 200
# 'json(obj, status)' - function to return JSON response. Status code defaults to 200
@@ -12,17 +12,17 @@ import json
def main(request, response):
return response.json({
'APPWRITE_FUNCTION_ID' : request.env['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' : request.env['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' : request.env['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' : request.env['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' : request.env['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' : request.env['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' : request.env['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' : request.env['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_DATA' : request.env['APPWRITE_FUNCTION_DATA'],
'APPWRITE_FUNCTION_USER_ID' : request.env['APPWRITE_FUNCTION_USER_ID'],
'APPWRITE_FUNCTION_JWT' : request.env['APPWRITE_FUNCTION_JWT'],
'APPWRITE_FUNCTION_PROJECT_ID' : request.env['APPWRITE_FUNCTION_PROJECT_ID'],
'CUSTOM_VARIABLE' : request.env['CUSTOM_VARIABLE'],
'APPWRITE_FUNCTION_ID' : request.variables['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' : request.variables['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' : request.variables['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' : request.variables['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' : request.variables['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' : request.variables['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' : request.variables['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' : request.variables['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_DATA' : request.variables['APPWRITE_FUNCTION_DATA'],
'APPWRITE_FUNCTION_USER_ID' : request.variables['APPWRITE_FUNCTION_USER_ID'],
'APPWRITE_FUNCTION_JWT' : request.variables['APPWRITE_FUNCTION_JWT'],
'APPWRITE_FUNCTION_PROJECT_ID' : request.variables['APPWRITE_FUNCTION_PROJECT_ID'],
'CUSTOM_VARIABLE' : request.variables['CUSTOM_VARIABLE'],
})
+14 -14
View File
@@ -2,7 +2,7 @@
'req' variable has:
'headers' - object with request headers
'payload' - object with request body data
'env' - object with environment variables
'variables' - object with function variables
'res' variable has:
'send(text, status)' - function to return text response. Status code defaults to 200
'json(obj, status)' - function to return JSON response. Status code defaults to 200
@@ -12,18 +12,18 @@
def main(request, response)
return response.json({
'APPWRITE_FUNCTION_ID' => request.env['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' => request.env['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' => request.env['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' => request.env['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' => request.env['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => request.env['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' => request.env['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' => request.env['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_DATA' => request.env['APPWRITE_FUNCTION_DATA'],
'APPWRITE_FUNCTION_USER_ID' => request.env['APPWRITE_FUNCTION_USER_ID'],
'APPWRITE_FUNCTION_JWT' => request.env['APPWRITE_FUNCTION_JWT'],
'APPWRITE_FUNCTION_PROJECT_ID' => request.env['APPWRITE_FUNCTION_PROJECT_ID'],
'CUSTOM_VARIABLE' => request.env['CUSTOM_VARIABLE']
'APPWRITE_FUNCTION_ID' => request.variables['APPWRITE_FUNCTION_ID'],
'APPWRITE_FUNCTION_NAME' => request.variables['APPWRITE_FUNCTION_NAME'],
'APPWRITE_FUNCTION_DEPLOYMENT' => request.variables['APPWRITE_FUNCTION_DEPLOYMENT'],
'APPWRITE_FUNCTION_TRIGGER' => request.variables['APPWRITE_FUNCTION_TRIGGER'],
'APPWRITE_FUNCTION_RUNTIME_NAME' => request.variables['APPWRITE_FUNCTION_RUNTIME_NAME'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => request.variables['APPWRITE_FUNCTION_RUNTIME_VERSION'],
'APPWRITE_FUNCTION_EVENT' => request.variables['APPWRITE_FUNCTION_EVENT'],
'APPWRITE_FUNCTION_EVENT_DATA' => request.variables['APPWRITE_FUNCTION_EVENT_DATA'],
'APPWRITE_FUNCTION_DATA' => request.variables['APPWRITE_FUNCTION_DATA'],
'APPWRITE_FUNCTION_USER_ID' => request.variables['APPWRITE_FUNCTION_USER_ID'],
'APPWRITE_FUNCTION_JWT' => request.variables['APPWRITE_FUNCTION_JWT'],
'APPWRITE_FUNCTION_PROJECT_ID' => request.variables['APPWRITE_FUNCTION_PROJECT_ID'],
'CUSTOM_VARIABLE' => request.variables['CUSTOM_VARIABLE']
})
end
+13 -13
View File
@@ -1,17 +1,17 @@
func main(req: RequestValue, res: RequestResponse) throws -> RequestResponse {
return res.json(data: [
"APPWRITE_FUNCTION_ID": req.env["APPWRITE_FUNCTION_ID"],
"APPWRITE_FUNCTION_NAME": req.env["APPWRITE_FUNCTION_NAME"],
"APPWRITE_FUNCTION_DEPLOYMENT": req.env["APPWRITE_FUNCTION_DEPLOYMENT"],
"APPWRITE_FUNCTION_TRIGGER": req.env["APPWRITE_FUNCTION_TRIGGER"],
"APPWRITE_FUNCTION_RUNTIME_NAME": req.env["APPWRITE_FUNCTION_RUNTIME_NAME"],
"APPWRITE_FUNCTION_RUNTIME_VERSION": req.env["APPWRITE_FUNCTION_RUNTIME_VERSION"],
"APPWRITE_FUNCTION_EVENT": req.env["APPWRITE_FUNCTION_EVENT"],
"APPWRITE_FUNCTION_EVENT_DATA": req.env["APPWRITE_FUNCTION_EVENT_DATA"],
"APPWRITE_FUNCTION_DATA": req.env["APPWRITE_FUNCTION_DATA"],
"APPWRITE_FUNCTION_USER_ID": req.env["APPWRITE_FUNCTION_USER_ID"],
"APPWRITE_FUNCTION_JWT": req.env["APPWRITE_FUNCTION_JWT"],
"APPWRITE_FUNCTION_PROJECT_ID": req.env["APPWRITE_FUNCTION_PROJECT_ID"],
"CUSTOM_VARIABLE": req.env["CUSTOM_VARIABLE"]
"APPWRITE_FUNCTION_ID": req.variables["APPWRITE_FUNCTION_ID"],
"APPWRITE_FUNCTION_NAME": req.variables["APPWRITE_FUNCTION_NAME"],
"APPWRITE_FUNCTION_DEPLOYMENT": req.variables["APPWRITE_FUNCTION_DEPLOYMENT"],
"APPWRITE_FUNCTION_TRIGGER": req.variables["APPWRITE_FUNCTION_TRIGGER"],
"APPWRITE_FUNCTION_RUNTIME_NAME": req.variables["APPWRITE_FUNCTION_RUNTIME_NAME"],
"APPWRITE_FUNCTION_RUNTIME_VERSION": req.variables["APPWRITE_FUNCTION_RUNTIME_VERSION"],
"APPWRITE_FUNCTION_EVENT": req.variables["APPWRITE_FUNCTION_EVENT"],
"APPWRITE_FUNCTION_EVENT_DATA": req.variables["APPWRITE_FUNCTION_EVENT_DATA"],
"APPWRITE_FUNCTION_DATA": req.variables["APPWRITE_FUNCTION_DATA"],
"APPWRITE_FUNCTION_USER_ID": req.variables["APPWRITE_FUNCTION_USER_ID"],
"APPWRITE_FUNCTION_JWT": req.variables["APPWRITE_FUNCTION_JWT"],
"APPWRITE_FUNCTION_PROJECT_ID": req.variables["APPWRITE_FUNCTION_PROJECT_ID"],
"CUSTOM_VARIABLE": req.variables["CUSTOM_VARIABLE"]
])
}
+53 -41
View File
@@ -353,16 +353,58 @@ class AuthTest extends TestCase
'$id' => ID::custom('123'),
'memberships' => [
[
'confirm' => true,
'$id' => ID::custom('456'),
'teamId' => ID::custom('abc'),
'confirm' => true,
'roles' => [
'administrator',
'moderator'
]
],
[
'confirm' => true,
'$id' => ID::custom('abc'),
'teamId' => ID::custom('def'),
'confirm' => true,
'roles' => [
'guest'
]
]
]
]);
$roles = Auth::getRoles($user);
$this->assertCount(9, $roles);
$this->assertContains(Role::users()->toString(), $roles);
$this->assertContains(Role::user(ID::custom('123'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('abc'), 'administrator')->toString(), $roles);
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
$this->assertContains(Role::member(ID::custom('456'))->toString(), $roles);
$this->assertContains(Role::member(ID::custom('abc'))->toString(), $roles);
}
public function testPrivilegedUserRoles(): void
{
Authorization::setRole(Auth::USER_ROLE_OWNER);
$user = new Document([
'$id' => ID::custom('123'),
'memberships' => [
[
'$id' => ID::custom('def'),
'teamId' => ID::custom('abc'),
'confirm' => true,
'roles' => [
'administrator',
'moderator'
]
],
[
'$id' => ID::custom('abc'),
'teamId' => ID::custom('def'),
'confirm' => true,
'roles' => [
'guest'
]
@@ -373,42 +415,6 @@ class AuthTest extends TestCase
$roles = Auth::getRoles($user);
$this->assertCount(7, $roles);
$this->assertContains(Role::users()->toString(), $roles);
$this->assertContains(Role::user(ID::custom('123'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('abc'), 'administrator')->toString(), $roles);
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
}
public function testPrivilegedUserRoles(): void
{
Authorization::setRole(Auth::USER_ROLE_OWNER);
$user = new Document([
'$id' => ID::custom('123'),
'memberships' => [
[
'confirm' => true,
'teamId' => ID::custom('abc'),
'roles' => [
'administrator',
'moderator'
]
],
[
'confirm' => true,
'teamId' => ID::custom('def'),
'roles' => [
'guest'
]
]
]
]);
$roles = Auth::getRoles($user);
$this->assertCount(5, $roles);
$this->assertNotContains(Role::users()->toString(), $roles);
$this->assertNotContains(Role::user(ID::custom('123'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
@@ -416,6 +422,8 @@ class AuthTest extends TestCase
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
$this->assertContains(Role::member(ID::custom('def'))->toString(), $roles);
$this->assertContains(Role::member(ID::custom('abc'))->toString(), $roles);
}
public function testAppUserRoles(): void
@@ -425,16 +433,18 @@ class AuthTest extends TestCase
'$id' => ID::custom('123'),
'memberships' => [
[
'confirm' => true,
'$id' => ID::custom('def'),
'teamId' => ID::custom('abc'),
'confirm' => true,
'roles' => [
'administrator',
'moderator'
]
],
[
'confirm' => true,
'$id' => ID::custom('abc'),
'teamId' => ID::custom('def'),
'confirm' => true,
'roles' => [
'guest'
]
@@ -444,7 +454,7 @@ class AuthTest extends TestCase
$roles = Auth::getRoles($user);
$this->assertCount(5, $roles);
$this->assertCount(7, $roles);
$this->assertNotContains(Role::users()->toString(), $roles);
$this->assertNotContains(Role::user(ID::custom('123'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
@@ -452,5 +462,7 @@ class AuthTest extends TestCase
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
$this->assertContains(Role::member(ID::custom('def'))->toString(), $roles);
$this->assertContains(Role::member(ID::custom('abc'))->toString(), $roles);
}
}
+12 -10
View File
@@ -54,8 +54,9 @@ class MessagingChannelsTest extends TestCase
'$id' => ID::custom('user' . $this->connectionsCount),
'memberships' => [
[
'confirm' => true,
'$id' => ID::custom('member' . $i),
'teamId' => ID::custom('team' . $i),
'confirm' => true,
'roles' => [
empty($index % 2)
? Auth::USER_ROLE_ADMIN
@@ -122,11 +123,11 @@ class MessagingChannelsTest extends TestCase
* Check for correct amount of subscriptions:
* - XXX users
* - XXX teams
* - XXX team roles (2 roles per team)
* - XXX team roles (3 roles per team)
* - 1 guests
* - 1 users
*/
$this->assertCount(($this->connectionsAuthenticated + (3 * $this->connectionsPerChannel) + 2), $this->realtime->subscriptions['1']);
$this->assertCount(($this->connectionsAuthenticated + (4 * $this->connectionsPerChannel) + 2), $this->realtime->subscriptions['1']);
/**
* Check for connections
@@ -138,7 +139,7 @@ class MessagingChannelsTest extends TestCase
$this->realtime->unsubscribe(-1);
$this->assertCount($this->connectionsTotal, $this->realtime->connections);
$this->assertCount(($this->connectionsAuthenticated + (3 * $this->connectionsPerChannel) + 2), $this->realtime->subscriptions['1']);
$this->assertCount(($this->connectionsAuthenticated + (4 * $this->connectionsPerChannel) + 2), $this->realtime->subscriptions['1']);
for ($i = 0; $i < $this->connectionsCount; $i++) {
$this->realtime->unsubscribe($i);
@@ -259,6 +260,7 @@ class MessagingChannelsTest extends TestCase
for ($i = 0; $i < $this->connectionsPerChannel; $i++) {
$permissions[] = Role::team(ID::custom('team' . $i))->toString();
$permissions[] = Role::member(ID::custom('member' . $i))->toString();
}
$event = [
'project' => '1',
@@ -284,13 +286,13 @@ class MessagingChannelsTest extends TestCase
$this->assertStringEndsWith($index, $receiver);
}
$role = empty($index % 2)
? Auth::USER_ROLE_ADMIN
: 'member';
$permissions = [
Role::team(
ID::custom('team' . $index),
(empty($index % 2)
? Auth::USER_ROLE_ADMIN
: 'member')
)->toString()
Role::team(ID::custom('team' . $index), $role)->toString(),
Role::member(ID::custom('member' . $index))->toString()
];
$event = [